30 using namespace gtsam;
36 static
Point3 P(0.2, 0.7, -2.0);
49 Matrix R = (
Matrix(3, 3) << 0, 1, 0, 1, 0, 0, 0, 0, -1).finished();
65 Matrix R = (
Matrix(3, 3) << 0, 1, 0, 1, 0, 0, 0, 0, -1).finished();
83 Rot3 R(0, 1, 0, 1, 0, 0, 0, 0, -1);
100 if (t < 1
e-5)
return Rot3();
101 Matrix3
R = I_3x3 +
sin(t) * J + (1.0 -
cos(t)) * (J * J);
109 double angle = 3.14 / 4.0;
112 -0.706825, 0, 0.707388);
113 Rot3 actual = Rot3::AxisAngle(axis, angle);
115 Rot3 actual2 = Rot3::AxisAngle(axis, angle-2*
M_PI);
119 Rot3 actual3 = Rot3::AxisAngle(axis, angle);
127 Rot3 R1(-0.999957, 0.00922903, 0.00203116, 0.00926964, 0.999739, 0.0208927, -0.0018374, 0.0209105, -0.999781);
130 const auto [actualAxis, actualAngle] = R1.
axisAngle();
132 double expectedAngle = 3.1396582;
149 double angle = 3.14 / 4.0;
152 -0.706825, 0, 0.707388);
153 Rot3 actual = Rot3::AxisAngle(axis, angle);
155 Rot3 actual2 = Rot3::Rodrigues(angle*axis);
163 Rot3 R1 = Rot3::AxisAngle(w / w.norm(), w.norm());
172 double angle =
M_PI/2.0;
173 Rot3 actual = Rot3::AxisAngle(axis, angle);
196 static const double PI =
std::acos(-1.0);
200 #define CHECK_OMEGA(X, Y, Z) \ 201 w = (Vector(3) << (X), (Y), (Z)).finished(); \ 202 R = Rot3::Rodrigues(w); \ 203 EXPECT(assert_equal(w, Rot3::Logmap(R), 1e-12)); 209 double norm =
sqrt(1.0 + 16.0 + 4.0);
210 double x = 1.0 / norm,
y = 4.0 / norm,
z = 2.0 / norm;
234 w = (
Vector(3) << x * PI, y * PI, z * PI).finished();
235 R = Rot3::Rodrigues(w);
242 #define CHECK_OMEGA_ZERO(X, Y, Z) \ 243 w = (Vector(3) << (X), (Y), (Z)).finished(); \ 244 R = Rot3::Rodrigues(w); \ 245 EXPECT(assert_equal((Vector)Z_3x1, Rot3::Logmap(R))); 254 Rot3 Rlund(-0.98582676, -0.03958746, -0.16303092,
255 -0.03997006, -0.88835923, 0.45740671,
256 -0.16293753, 0.45743998, 0.87418537);
261 #if defined(GTSAM_USE_QUATERNIONS) 264 (
Vector)Rot3::Logmap(Rlund), 1
e-8));
268 (
Vector)Rot3::Logmap(Rlund), 1
e-8));
275 Vector3 d12 = Vector3::Constant(0.1);
282 Vector d12 = Vector3::Constant(0.1);
293 Vector d21 = t2.localCoordinates(t1);
300 Rot3 gR1 = Rot3::Rodrigues(0.1, 0.4, 0.2);
301 Rot3 gR2 = Rot3::Rodrigues(0.3, 0.1, 0.7);
330 template <
typename Derived>
357 Matrix actualDrotate1a, actualDrotate1b, actualDrotate2;
358 R.
rotate(
P, actualDrotate1a, actualDrotate2);
386 Rot3 R1 = Rot3::Rodrigues(0.1, 0.2, 0.3);
387 Rot3 R2 = Rot3::Rodrigues(0.2, 0.3, 0.5);
390 Matrix actualH1, actualH2;
406 Rot3 R = Rot3::Rodrigues(0.1, 0.2, 0.3);
426 0.5, -
sqrt(3.0)/2.0, 0.0,
427 sqrt(3.0)/2.0, 0.5, 0.0,
428 0.0, 0.0, 1.0).finished();
431 Rot3 R = Rot3::Rodrigues(0.1, 0.4, 0.2);
436 Rot3 R1 = Rot3::Rodrigues(0.1, 0.2, 0.3);
437 Rot3 R2 = Rot3::Rodrigues(0.2, 0.3, 0.5);
440 Matrix actualH1, actualH2;
454 double t = 0.1, st =
sin(t), ct =
cos(t);
462 Rot3 expected1(1, 0, 0, 0, ct, -st, 0, st, ct);
468 Rot3 expected2(ct, 0, st, 0, 1, 0, -st, 0, ct);
474 Rot3 expected3(ct, -st, 0, st, ct, 0, 0, 0, 1);
478 Rot3 expected = Rot3::Rz(0.3) * Rot3::Ry(0.2) * Rot3::Rx(0.1);
497 Rot3 expected = Rot3::Yaw(0.1) * Rot3::Pitch(0.2) * Rot3::Roll(0.3);
507 const auto [actualK, actual] =
RQ(
R.
matrix());
526 Matrix K = (
Matrix(3, 3) << 500.0, 0.0, 320.0, 0.0, 500.0, 240.0, 0.0, 0.0, 1.0).finished();
528 const auto [actualK2, actual2] =
RQ(A);
536 double theta = w.norm();
537 double theta2 = theta*theta;
541 -
w(1),
w(0), 0.0 ).finished();
543 Matrix Rmat = I_3x3 + (1.0-theta2/6.0 + theta2*theta2/120.0
544 - theta2*theta2*theta2/5040.0)*W + (0.5 - theta2/24.0 + theta2*theta2/720.0)*W2 ;
558 Vector actualw = Rot3::Logmap(R);
565 Quaternion q1(0.710997408193224, 0.360544029310185, 0.594459869568306, 0.105395217842782);
566 Rot3 R1(0.271018623057411, 0.278786459830371, 0.921318086098018,
567 0.578529366719085, 0.717799701969298, -0.387385285854279,
568 -0.769319620053772, 0.637998195662053, 0.033250932803219);
570 Quaternion q2(0.263360579192421, 0.571813128030932, 0.494678363680335,
572 Rot3 R2(-0.207341903877828, 0.250149415542075, 0.945745528564780,
573 0.881304914479026, -0.371869043667957, 0.291573424846290,
574 0.424630407073532, 0.893945571198514, -0.143353873763946);
603 const Matrix I = Matrix::Identity(n,n);
618 std::ostringstream
os;
620 string expected =
"[\n\t1, 0, 0;\n\t0, 1, 0;\n\t0, 0, 1\n]";
628 Rot3 R1 = Rot3::Rz(1),
R2 = Rot3::Rz(2),
R3 = Rot3::Rz(1.5);
645 EXPECT(check_group_invariants(
id,
id));
646 EXPECT(check_group_invariants(
id,
T1));
647 EXPECT(check_group_invariants(
T2,
id));
651 EXPECT(check_manifold_invariants(
id,
id));
652 EXPECT(check_manifold_invariants(
id,
T1));
653 EXPECT(check_manifold_invariants(
T2,
id));
681 M << 0.79067393, 0.6051136, -0.0930814,
682 0.4155925, -0.64214347, -0.64324489,
683 -0.44948549, 0.47046326, -0.75917576;
686 expected << 0.790687, 0.605096, -0.0931312,
687 0.415746, -0.642355, -0.643844,
688 -0.449411, 0.47036, -0.759468;
690 auto actual = Rot3::ClosestTo(3*M);
700 #define CHECK_AXIS_ANGLE(expectedAxis, expectedAngle, rotation) \ 701 std::tie(actualAxis, actualAngle) = rotation.axisAngle(); \ 702 EXPECT(assert_equal(expectedAxis, actualAxis, 1e-9)); \ 703 EXPECT_DOUBLES_EQUAL(expectedAngle, actualAngle, 1e-9); \ 704 EXPECT(assert_equal(rotation, Rot3::AxisAngle(expectedAxis, expectedAngle))) 708 Unit3 axis(omega), _axis(-omega);
724 const double theta270 =
M_PI +
M_PI / 2;
731 const double theta_270 = -(
M_PI +
M_PI / 2);
737 const double theta195 = 195 *
M_PI / 180;
738 const double theta165 = 165 *
M_PI / 180;
755 return Rot3::RzRyRx(a, b, c);
759 const auto x = 0.1,
y = 0.4,
z = 0.2;
765 Rot3::RzRyRx(
x,
y,
z, act_x, act_y, act_z);
776 const auto xyz =
Vector3{-0.3, 0.1, 0.7};
780 Rot3::RzRyRx(xyz, act);
787 return Rot3::Ypr(y, p, r);
791 const auto y = 0.7,
p = -0.3, r = 0.1;
797 Rot3::Ypr(
y,
p, r, act_y, act_p, act_r);
806 const auto RQ_ypr =
RQ(R);
807 return RQ_ypr.second;
811 using VecAndErr = std::pair<Vector3, double>;
812 std::vector<VecAndErr> test_xyz;
814 test_xyz.push_back(VecAndErr{{0, 0, 0},
error});
815 test_xyz.push_back(VecAndErr{{0, 0.5, -0.5},
error});
816 test_xyz.push_back(VecAndErr{{0.3, 0, 0.2},
error});
817 test_xyz.push_back(VecAndErr{{-0.6, 1.3, 0}, 1
e-8});
818 test_xyz.push_back(VecAndErr{{1.0, 0.7, 0.8},
error});
819 test_xyz.push_back(VecAndErr{{3.0, 0.7, -0.6},
error});
820 test_xyz.push_back(VecAndErr{{
M_PI / 2, 0, 0},
error});
821 test_xyz.push_back(VecAndErr{{0, 0,
M_PI / 2},
error});
824 test_xyz.push_back(VecAndErr{{0,
M_PI / 2 - 1
e-1, 0}, 1
e-7});
825 test_xyz.push_back(VecAndErr{{0, 3 *
M_PI / 2 + 1
e-1, 0}, 1
e-7});
826 test_xyz.push_back(VecAndErr{{0,
M_PI / 2 - 1.1e-2, 0}, 1
e-4});
827 test_xyz.push_back(VecAndErr{{0, 3 *
M_PI / 2 + 1.1e-2, 0}, 1
e-4});
829 for (
auto const& vec_err : test_xyz) {
830 auto const& xyz = vec_err.first;
832 const auto R = Rot3::RzRyRx(xyz).
matrix();
837 const auto err = vec_err.second;
846 const auto aa =
Vector3{-0.6, 0.3, 0.2};
859 const auto aa =
Vector3{0.1, -0.3, -0.2};
872 const auto aa =
Vector3{1.2, 0.3, -0.9};
885 const auto aa =
Vector3{0.8, -0.8, 0.8};
898 const auto aa =
Vector3{0.01, 0.1, 0.0};
911 const auto aa =
Vector3{0.0, 0.1, 0.6};
924 Rot3 R_w1 = Rot3::Ry(degree *
M_PI / 180);
929 for (
size_t i = 2;
i < 360; ++
i) {
934 actual = R_w2.
matrix().determinant();
#define CHECK_OMEGA_ZERO(X, Y, Z)
EIGEN_DEVICE_FUNC Coefficients & coeffs()
Rot3 RzRyRx_proxy(double const &a, double const &b, double const &c)
Matrix< RealScalar, Dynamic, Dynamic > M
EIGEN_DEVICE_FUNC CoeffReturnType x() const
Jet< T, N > cos(const Jet< T, N > &f)
static const Eigen::MatrixBase< Vector3 >::ConstantReturnType Z_3x1
#define GTSAM_CONCEPT_ASSERT(concept)
Concept check for values that can be used in unit tests.
AngularVelocity bracket(const AngularVelocity &X, const AngularVelocity &Y)
Provides convenient mappings of common member functions for testing.
static int runAllTests(TestResult &result)
T between(const T &t1, const T &t2)
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set set set set surface set nocontour set clabel set mapping cartesian set nohidden3d set cntrparam order set cntrparam linear set cntrparam levels auto set cntrparam points set size set origin
bool equals(const Rot3 &p, double tol=1e-9) const
void determinant(const MatrixType &m)
EIGEN_DONT_INLINE Scalar zero()
Matrix Cayley(const Matrix &A)
double pitch(OptionalJacobian< 1, 3 > H={}) const
Vector3 xyz_proxy(Rot3 const &R)
EIGEN_DEVICE_FUNC CoeffReturnType z() const
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Jet< T, N > acos(const Jet< T, N > &f)
Jet< T, N > sin(const Jet< T, N > &f)
static Cal3_S2 K(500, 500, 0.1, 640/2, 480/2)
Pose2_ Expmap(const Vector3_ &xi)
EIGEN_DEVICE_FUNC CoeffReturnType w() const
Some functions to compute numerical derivatives.
static const Pose3 T2(Rot3::Rodrigues(0.3, 0.2, 0.1), P2)
T BCH(const T &X, const T &Y)
AGC: bracket() only appears in Rot3 tests, should this be used elsewhere?
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
EIGEN_DEVICE_FUNC const LogReturnType log() const
Rot3 is a 3D rotation represented as a rotation matrix if the preprocessor symbol GTSAM_USE_QUATERNIO...
#define GTSAM_CONCEPT_LIE_INST(T)
#define EXPECT_DOUBLES_EQUAL(expected, actual, threshold)
static const Similarity3 id
EIGEN_DEVICE_FUNC const InverseReturnType inverse() const
internal::FixedSizeMatrix< Y, X >::type numericalDerivative11(std::function< Y(const X &)> h, const X &x, double delta=1e-5)
New-style numerical derivatives using manifold_traits.
T compose(const T &t1, const T &t2)
internal::FixedSizeMatrix< Y, X1 >::type numericalDerivative21(const std::function< Y(const X1 &, const X2 &)> &h, const X1 &x1, const X2 &x2, double delta=1e-5)
Vector3 RQ_proxy(Matrix3 const &R)
Rot3 slerp(double t, const Rot3 &other) const
Spherical Linear intERPolation between *this and other.
#define CHECK_LIE_GROUP_DERIVATIVES(t1, t2)
pair< Matrix3, Vector3 > RQ(const Matrix3 &A, OptionalJacobian< 3, 9 > H)
Rot3 inverse() const
inverse of a rotation
#define CHECK_OMEGA(X, Y, Z)
TangentVector localCoordinates(const Class &g) const
localCoordinates as required by manifold concept: finds tangent vector between *this and g ...
Represents a 3D point on a unit sphere.
internal::FixedSizeMatrix< Y, X3 >::type numericalDerivative33(std::function< Y(const X1 &, const X2 &, const X3 &)> h, const X1 &x1, const X2 &x2, const X3 &x3, double delta=1e-5)
Point3 unrotate(const Point3 &p, OptionalJacobian< 3, 3 > H1={}, OptionalJacobian< 3, 3 > H2={}) const
rotate point from world to rotated frame
Vector3 xyz(OptionalJacobian< 3, 3 > H={}) const
P unrotate(const T &r, const P &pt)
double roll_proxy(Rot3 const &R)
internal::FixedSizeMatrix< Y, X2 >::type numericalDerivative32(std::function< Y(const X1 &, const X2 &, const X3 &)> h, const X1 &x1, const X2 &x2, const X3 &x3, double delta=1e-5)
AngularVelocity(const Eigen::MatrixBase< Derived > &v)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
#define EXPECT(condition)
Array< int, Dynamic, 1 > v
Vector3 ypr_proxy(Rot3 const &R)
internal::FixedSizeMatrix< Y, X1 >::type numericalDerivative31(std::function< Y(const X1 &, const X2 &, const X3 &)> h, const X1 &x1, const X2 &x2, const X3 &x3, double delta=1e-5)
Vector3 rpy(OptionalJacobian< 3, 3 > H={}) const
Vector::Scalar omega(const Vector &t, const Vector &s, RealScalar angle)
Array< double, 1, 3 > e(1./3., 0.5, 2.)
Rot3 slow_but_correct_Rodrigues(const Vector &w)
static Point3 P(0.2, 0.7, -2.0)
#define ROT3_DEFAULT_COORDINATES_MODE
JacobiRotation< float > J
EIGEN_DEVICE_FUNC CoeffReturnType y() const
Class compose(const Class &g) const
double roll(OptionalJacobian< 1, 3 > H={}) const
std::pair< Unit3, double > axisAngle() const
gtsam::Quaternion toQuaternion() const
double yaw_proxy(Rot3 const &R)
Matrix3 skewSymmetric(double wx, double wy, double wz)
ofstream os("timeSchurFactors.csv")
Class retract(const TangentVector &v) const
retract as required by manifold concept: applies v at *this
The quaternion class used to represent 3D orientations and rotations.
static const Similarity3 T1(R, Point3(3.5, -8.2, 4.2), 1)
Class between(const Class &g) const
#define CHECK_AXIS_ANGLE(expectedAxis, expectedAngle, rotation)
Rot3 Ypr_proxy(double const &y, double const &p, double const &r)
#define CHECK_CHART_DERIVATIVES(t1, t2)
internal::FixedSizeMatrix< Y, X2 >::type numericalDerivative22(std::function< Y(const X1 &, const X2 &)> h, const X1 &x1, const X2 &x2, double delta=1e-5)
Class expmap(const TangentVector &v) const
double yaw(OptionalJacobian< 1, 3 > H={}) const
Vector3 ypr(OptionalJacobian< 3, 3 > H={}) const
Jet< T, N > sqrt(const Jet< T, N > &f)
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > Matrix
TangentVector logmap(const Class &g) const
Point3 rotate(const Point3 &p, OptionalJacobian< 3, 3 > H1={}, OptionalJacobian< 3, 3 > H2={}) const
AngularVelocity(double wx, double wy, double wz)
double pitch_proxy(Rot3 const &R)
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
Base class for all dense matrices, vectors, and expressions.
#define GTSAM_CONCEPT_TESTABLE_INST(T)
3D rotation represented as a rotation matrix or quaternion
Eigen::Quaternion< double, Eigen::DontAlign > Quaternion
Vector3 rpy_proxy(Rot3 const &R)