3#include <Eigen/Geometry>
8 typedef Eigen::Matrix <g_type, 7, 1>
Vector7d;
9 typedef Eigen::Matrix <g_type, 7, 7>
Matrix7d;
14 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
44 Sim3(
const Matrix3<g_type>& R,
const Vector3<g_type>&
t, g_type
s)
55 Vector3<g_type> omega;
56 for (
int i = 0; i < 3; i++)
59 Vector3<g_type> upsilon;
60 for (
int i = 0; i < 3; i++)
61 upsilon[i] = update[i + 3];
64 g_type theta = omega.norm();
65 Matrix3<g_type> Omega =
skew(omega);
67 Matrix3<g_type> Omega2 = Omega * Omega;
72 g_type eps = g_type(0.00001);
74 if (fabs(sigma) < eps)
81 R = (I + Omega + Omega * Omega);
85 g_type theta2 = theta * theta;
86 A = (1 -
cos(theta)) / (theta2);
87 B = (theta -
sin(theta)) / (theta2 * theta);
88 R = I +
sin(theta) / theta * Omega + (1 -
cos(theta)) / (theta * theta) * Omega2;
96 g_type sigma2 = sigma * sigma;
97 A = ((sigma - 1) *
s + 1) / sigma2;
98 B = ((g_type(0.5) * sigma2 - sigma + 1) *
s) / (sigma2 * sigma);
99 R = (I + Omega + Omega2);
103 R = I +
sin(theta) / theta * Omega + (1 -
cos(theta)) / (theta * theta) * Omega2;
107 g_type a =
s *
sin(theta);
108 g_type b =
s *
cos(theta);
109 g_type theta2 = theta * theta;
110 g_type sigma2 = sigma * sigma;
112 g_type c = theta2 + sigma2;
113 A = (a * sigma + (1 - b) * theta) / (theta * c);
114 B = (C - ((b - 1) * sigma + a * theta) / (c)) * g_type(1.) / (theta2);
122 Matrix3<g_type> W = A * Omega + B * Omega2 + C * I;
129 Vector3<g_type>
map(
const Vector3<g_type>& xyz)
const {
130 return s * (
r * xyz) +
t;
138 g_type sigma = std::log(
s);
139 Vector3<g_type> omega;
140 Vector3<g_type> upsilon;
143 Matrix3<g_type> R =
r.toRotationMatrix();
144 g_type d = g_type(0.5) * (R(0, 0) + R(1, 1) + R(2, 2) - 1);
146 Matrix3<g_type> Omega;
148 g_type eps = g_type(0.00001);
149 Matrix3<g_type> I = Matrix3<g_type>::Identity();
152 if (fabs(sigma) < eps)
159 A = g_type(1.0 / 2.0);
160 B = g_type(1.0 / 6.0);
164 g_type theta = acos(d);
165 g_type theta2 = theta * theta;
166 omega = theta / (2 *
sqrt(1 - d * d)) *
deltaR(R);
168 A = (1 -
cos(theta)) / (theta2);
169 B = (theta -
sin(theta)) / (theta2 * theta);
178 g_type sigma2 = sigma * sigma;
181 A = ((sigma - 1) *
s + 1) / (sigma2);
182 B = ((g_type(0.5) * sigma2 - sigma + 1) *
s) / (sigma2 * sigma);
186 g_type theta = acos(d);
187 omega = theta / (2 *
sqrt(1 - d * d)) *
deltaR(R);
189 g_type theta2 = theta * theta;
190 g_type a =
s *
sin(theta);
191 g_type b =
s *
cos(theta);
192 g_type c = theta2 + sigma * sigma;
193 A = (a * sigma + (1 - b) * theta) / (theta * c);
194 B = (C - ((b - 1) * sigma + a * theta) / (c)) * g_type(1.) / (theta2);
198 Matrix3<g_type> W = A * Omega + B * Omega * Omega + C * I;
200 upsilon = W.lu().solve(
t);
203 for (
int i = 0; i < 3; i++)
206 for (
int i = 0; i < 3; i++)
207 res[i + 3] = upsilon[i];
220 return Sim3(
r.conjugate(),
r.conjugate() * ((g_type(- 1.) /
s) *
t), g_type(1.) /
s);
231 return r.coeffs()[i];
246 return r.coeffs()[i];
260 ret.
t =
s * (
r * other.
t) +
t;
268 Sim3 ret = (*this) * other;
282 inline const g_type&
scale()
const {
return s; }
https://www.3dgep.com/understanding-quaternions/
The primary namespace for the NDEVR SDK.
Eigen::Matrix< g_type, 7, 1 > Vector7d
7D vector for quaternion + translation representation.
Vector3< g_type > deltaR(const Matrix3< g_type > &R)
Extracts the rotation vector from a rotation matrix using the Rodrigues formula.
Eigen::Matrix< g_type, 7, 7 > Matrix7d
7x7 matrix type for Sim3 operations.
Matrix3< g_type > skew(const Vector3< g_type > &v)
Computes the 3x3 skew-symmetric matrix from a 3D vector.
t_type sqrt(const t_type &value)
std::enable_if<!ObjectInfo< t_type >::Float, fltp08 >::type sin(const Angle< t_type > &angle)
Performs optimized sine operation on the given angle using pre-computed lookup table for optimal spee...
std::enable_if<!ObjectInfo< t_type >::Float, fltp08 >::type cos(const Angle< t_type > &angle)
Performs optimized cosine operation on the given angle using pre-computed lookup table for optimal sp...
constexpr t_to cast(const Angle< t_from > &value)
Casts an Angle from one backing type to another.
Sim3(const Quaternion< g_type > &r, const Vector3< g_type > &t, g_type s)
Constructs from a quaternion, translation, and scale.
Sim3 inverse() const
Computes the inverse of this similarity transform.
const g_type & scale() const
Returns a const reference to the scale factor.
Vector3< g_type > t
Translation component.
g_type operator[](int i) const
Const element access: indices 0-3 = quaternion, 4-6 = translation, 7 = scale.
g_type & scale()
Returns a mutable reference to the scale factor.
Vector3< g_type > map(const Vector3< g_type > &xyz) const
Applies the similarity transform to a 3D point: s * R * xyz + t.
Vector7d log() const
Computes the logarithmic map (Sim3 -> 7D tangent vector).
Sim3 operator*(const Sim3 &other) const
Composes two Sim3 transforms.
g_type & operator[](int i)
Mutable element access: indices 0-3 = quaternion, 4-6 = translation, 7 = scale.
Sim3(const Vector7d &update, bool fix_scale)
Constructs from a 7D tangent-space update vector.
Quaternion< g_type > r
Rotation component as a unit quaternion.
Sim3()
Default constructor.
Sim3(const Matrix3< g_type > &R, const Vector3< g_type > &t, g_type s)
Constructs from a rotation matrix, translation, and scale.
const Quaternion< g_type > & rotation() const
Returns a const reference to the rotation quaternion.
Vector3< g_type > & translation()
Returns a mutable reference to the translation.
Quaternion< g_type > & rotation()
Returns a mutable reference to the rotation quaternion.
Sim3 & operator*=(const Sim3 &other)
In-place composition with another Sim3 transform.
const Vector3< g_type > & translation() const
Returns a const reference to the translation.