24 #include <boost/math/constants/constants.hpp> 35 cout << (s.empty() ?
"R: " : s +
" ");
41 Unit3 axis = Unit3::Random(rng);
42 uniform_real_distribution<double> randomAngle(-
M_PI,
M_PI);
43 double angle = randomAngle(rng);
44 return AxisAngle(axis, angle);
59 throw std::runtime_error(
"AlignSinglePair: axis has Nans");
62 const Matrix3
P = I_3x3 - z * z.transpose();
67 const double u = x.dot(b_po);
68 const double v = y.dot(b_po);
70 return Rot3::AxisAngle(z, -angle);
82 Rot3 i_R_b = AlignPair(a_p.
cross(b_p), a_p, b_p);
86 Unit3 i_q = i_R_b * b_q;
90 Rot3 a_R_i = AlignPair(a_p, a_q, i_q);
95 Rot3 a_R_b = a_R_i * i_R_b;
100 bool Rot3::equals(
const Rot3 &
R,
double tol)
const {
114 if (Hp) *Hp = q.
basis().transpose() *
matrix() * Dp;
124 if (Hp) *Hp = q.
basis().transpose() *
matrix().transpose () * Dp;
125 if (HR) *HR = q.
basis().transpose() * q.
skew();
138 const Matrix3& Rt = transpose();
140 const double wx = q.x(), wy = q.y(), wz = q.z();
142 *H1 << 0.0, -wz, +wy, +wz, 0.0, -wx, -wy, +wx, 0.0;
157 throw invalid_argument(
"Argument to Rot3::column must be 1, 2, or 3");
166 #ifdef GTSAM_USE_QUATERNIONS 173 boost::tie(I, q) =
RQ(
m, qHm);
186 if (H) H->row(0).swap(H->row(2));
242 pair<Unit3, double> Rot3::axisAngle()
const {
243 const Vector3 omega = Rot3::Logmap(*
this);
244 return std::pair<Unit3, double>(
Unit3(omega), omega.norm());
249 return SO3::ExpmapDerivative(x);
254 return SO3::LogmapDerivative(x);
259 const double x = -
atan2(-A(2, 1), A(2, 2));
260 const auto Qx = Rot3::Rx(-x).matrix();
261 const Matrix3
B = A * Qx;
263 const double y = -
atan2(B(2, 0), B(2, 2));
264 const auto Qy = Rot3::Ry(-y).matrix();
265 const Matrix3
C = B * Qy;
267 const double z = -
atan2(-
C(1, 0),
C(1, 1));
268 const auto Qz = Rot3::Rz(-z).matrix();
269 const Matrix3
R = C * Qz;
273 throw std::runtime_error(
274 "Rot3::RQ : Derivative undefined at singularity (gimbal lock)");
276 auto atan_d1 = [](
double y,
double x) {
return x / (x * x + y *
y); };
277 auto atan_d2 = [](
double y,
double x) {
return -y / (x * x + y *
y); };
279 const auto sx = -Qx(2, 1),
cx = Qx(1, 1);
280 const auto sy = -Qy(0, 2),
cy = Qy(0, 0);
282 *H = Matrix39::Zero();
284 (*H)(0, 5) = atan_d1(A(2, 1), A(2, 2));
285 (*H)(0, 8) = atan_d2(A(2, 1), A(2, 2));
289 (*H)(1, 2) = -atan_d1(B(2, 0), B(2, 2));
290 const auto yHb22 = -atan_d2(B(2, 0), B(2, 2));
291 (*H)(1, 5) = yHb22 * sx;
292 (*H)(1, 8) = yHb22 *
cx;
297 const auto c10Hx = (A(1, 1) *
cx - A(1, 2) * sx) * sy;
298 const auto c10Hy = A(1, 2) *
cx *
cy + A(1, 1) *
cy * sx - A(1, 0) * sy;
299 Vector9 c10HA = c10Hx * H->row(0) + c10Hy * H->row(1);
304 const auto c11Hx = -A(1, 2) *
cx - A(1, 1) * sx;
305 Vector9 c11HA = c11Hx * H->row(0);
309 H->block<1, 9>(2, 0) =
310 atan_d1(
C(1, 0),
C(1, 1)) * c10HA + atan_d2(
C(1, 0),
C(1, 1)) * c11HA;
313 const auto xyz =
Vector3(x, y, z);
314 return make_pair(R, xyz);
void print(const Matrix &A, const string &s, ostream &stream)
Vector3_ operator*(const Double_ &s, const Vector3_ &v)
GTSAM_EXPORT const Matrix32 & basis(OptionalJacobian< 6, 2 > H=boost::none) const
EIGEN_DEVICE_FUNC CoeffReturnType x() const
EIGEN_DEVICE_FUNC CoeffReturnType y() const
Rot2 R(Rot2::fromAngle(0.1))
GTSAM_EXPORT Vector3 unitVector(OptionalJacobian< 3, 2 > H=boost::none) const
Return unit-norm Vector.
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 set xzeroaxis lt lw set x2zeroaxis lt lw set yzeroaxis lt lw set y2zeroaxis lt lw set tics in set ticslevel set tics set mxtics default set mytics default set mx2tics default set my2tics default set xtics border mirror norotate autofreq set ytics border mirror norotate autofreq set ztics border nomirror norotate autofreq set nox2tics set noy2tics set timestamp bottom norotate set rrange[*:*] noreverse nowriteback set trange[*:*] noreverse nowriteback set urange[*:*] noreverse nowriteback set vrange[*:*] noreverse nowriteback set xlabel matrix size set x2label set timefmt d m y n H
3*3 matrix representation of SO(3)
Matrix< SCALARB, Dynamic, Dynamic > B
EIGEN_DEVICE_FUNC CoeffReturnType w() const
EIGEN_DEVICE_FUNC CoeffReturnType z() const
Represents a 3D point on a unit sphere.
T interpolate(const T &X, const T &Y, double t)
const Eigen::IOFormat & matlabFormat()
pair< Matrix3, Vector3 > RQ(const Matrix3 &A, OptionalJacobian< 3, 9 > H)
P unrotate(const T &r, const P &pt)
P rotate(const T &r, const P &pt)
Array< double, 1, 3 > e(1./3., 0.5, 2.)
EIGEN_DEVICE_FUNC const Scalar & q
GTSAM_EXPORT Point3 point3(OptionalJacobian< 3, 2 > H=boost::none) const
Return unit-norm Point3.
Jet< T, N > atan2(const Jet< T, N > &g, const Jet< T, N > &f)
bool equal_with_abs_tol(const Eigen::DenseBase< MATRIX > &A, const Eigen::DenseBase< MATRIX > &B, double tol=1e-9)
Matrix< Scalar, Dynamic, Dynamic > C
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
ostream & operator<<(ostream &os, const Rot3 &R)
ofstream os("timeSchurFactors.csv")
The quaternion class used to represent 3D orientations and rotations.
Unit3 cross(const Unit3 &q) const
Cross-product between two Unit3s.
GTSAM_EXPORT double dot(const Unit3 &q, OptionalJacobian< 1, 2 > H1=boost::none, OptionalJacobian< 1, 2 > H2=boost::none) const
Return dot product with q.
Map< Matrix< T, Dynamic, Dynamic, ColMajor >, 0, OuterStride<> > matrix(T *data, int rows, int cols, int stride)
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
const MATRIX::ConstColXpr column(const MATRIX &A, size_t j)
3D rotation represented as a rotation matrix or quaternion
GTSAM_EXPORT Matrix3 skew() const
Return skew-symmetric associated with 3D point on unit sphere.