33#include <Eigen/Geometry>
36 using namespace Eigen;
44 EIGEN_MAKE_ALIGNED_OPERATOR_NEW;
63 SE3Quat(
const Matrix3<g_type>& R,
const Vector3<g_type>& t)
83 template <
typename Derived>
84 explicit SE3Quat(
const MatrixBase<Derived>& v)
86 assert((v.size() == 6 || v.size() == 7) &&
"Vector dimension does not match");
88 for (
int i=0; i<3; i++){
90 _r.coeffs()(i)=v[i+3];
96 g_type w2=1.-
_r.squaredNorm();
97 _r.w()= (w2<0.) ? 0. :
sqrt(w2);
100 else if (v.size() == 7) {
102 for (
int i=0; i<3; ++i, ++idx)
104 for (
int i=0; i<4; ++i, ++idx)
105 _r.coeffs()(i) = v(idx);
140 inline Vector3<g_type>
operator* (
const Vector3<g_type>& v)
const {
147 ret.
_r=
_r.conjugate();
157 return _r.coeffs()[i-3];
178 m_t=Vector3<g_type>(v[0], v[1], v[2]);
196 g_type w = g_type(1.)-v[3]*v[3]-v[4]*v[4]-v[5]*v[5];
202 m_t=Vector3<g_type>(v[0], v[1], v[2]);
211 Matrix3<g_type> _R =
_r.toRotationMatrix();
212 g_type d = g_type(0.5)*(_R(0,0)+_R(1,1)+_R(2,2)-1);
213 Vector3<g_type> omega;
214 Vector3<g_type> upsilon;
217 Vector3<g_type> dR =
deltaR(_R);
218 Matrix3<g_type> V_inv;
224 Matrix3<g_type> Omega =
skew(omega);
225 V_inv = Matrix3<g_type>::Identity()- 0.5*Omega + (1./12.)*(Omega*Omega);
229 g_type d_clamped = (d < g_type(-1.0)) ? g_type(-1.0) : ((d > g_type(1.0)) ? g_type(1.0) : d);
230 g_type theta = acos(d_clamped);
231 g_type sin_theta =
sqrt(g_type(1.0) - d_clamped * d_clamped);
232 if (sin_theta < g_type(1e-10))
235 omega = g_type(
PI<fltp08>() / 2.0) * dR.normalized();
236 Matrix3<g_type> Omega =
skew(omega);
237 V_inv = Matrix3<g_type>::Identity() - g_type(0.5) * Omega + (g_type(1.0) / g_type(12.0)) * (Omega * Omega);
241 omega = theta / (g_type(2.0) * sin_theta) * dR;
242 Matrix3<g_type> Omega =
skew(omega);
243 g_type half_theta = theta / g_type(2.0);
244 V_inv = ( Matrix3<g_type>::Identity() - g_type(0.5) * Omega
245 + ( g_type(1.0) - theta / (g_type(2.0) *
tan(half_theta))) / (theta * theta) * (Omega * Omega) );
250 for (
int i=0; i<3;i++){
253 for (
int i=0; i<3;i++){
263 Vector3<g_type>
map(
const Vector3<g_type>& xyz)
const
274 Vector3<g_type> omega;
275 for (
int i=0; i<3; i++)
277 Vector3<g_type> upsilon;
278 for (
int i=0; i<3; i++)
279 upsilon[i]=update[i+3];
281 g_type theta = omega.norm();
282 Matrix3<g_type> Omega =
skew(omega);
288 Matrix3<g_type> Omega2 = Omega*Omega;
289 R = (Matrix3<g_type>::Identity() + Omega + g_type(0.5)*Omega2);
290 V = (Matrix3<g_type>::Identity() + g_type(0.5)*Omega + g_type(1./6.)*Omega2);
294 Matrix3<g_type> Omega2 = Omega*Omega;
296 R = (Matrix3<g_type>::Identity()
297 +
sin(theta)/theta *Omega
298 + (1-
cos(theta))/(theta*theta)*Omega2);
300 V = (Matrix3<g_type>::Identity()
301 + (1-
cos(theta))/(theta*theta)*Omega
302 + (theta-
sin(theta))/(pow(theta,3))*Omega2);
309 Eigen::Matrix<g_type, 6, 6>
adj()
const
311 Matrix3<g_type> R =
_r.toRotationMatrix();
312 Eigen::Matrix<g_type, 6, 6> res;
313 res.block(0,0,3,3) = R;
314 res.block(3,3,3,3) = R;
315 res.block(3,0,3,3) =
skew(
m_t)*R;
316 res.block(0,3,3,3) = Matrix3<g_type>::Zero(3,3);
324 Eigen::Matrix<g_type,4,4> homogeneous_matrix;
325 homogeneous_matrix.setIdentity();
326 homogeneous_matrix.block(0,0,3,3) =
_r.toRotationMatrix();
329 return homogeneous_matrix;
343 operator Eigen::Transform<g_type, 3, 1>()
const
345 Eigen::Transform<g_type, 3, 1> result = (Eigen::Transform<g_type, 3, 1>)
rotation();
350 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
353 inline std::ostream& operator <<(std::ostream& out_str,
const SE3Quat& se3)
355 out_str << se3.to_homogeneous_matrix() << std::endl;
https://www.3dgep.com/understanding-quaternions/
SE(3) rigid body transformation represented by a unit quaternion and translation vector.
SE3Quat inverse() const
Computes the inverse of this SE3 transform.
const Quaternion< g_type > & rotation() const
Returns a const reference to the rotation quaternion.
SE3Quat(const Quaternion< g_type > &q, const Vector3< g_type > &t)
Constructs from a quaternion and translation vector.
Eigen::Matrix< g_type, 4, 4 > to_homogeneous_matrix() const
Converts to a 4x4 homogeneous transformation matrix.
Vector3< g_type > m_t
Translation component.
void normalizeRotation()
Normalizes the rotation quaternion, ensuring positive w.
g_type operator[](int i) const
Const element access: 0-2 = translation, 3-6 = quaternion coeffs.
Quaternion< g_type > _r
Rotation component as a unit quaternion.
Vector7d toVector() const
Converts to a 7D vector [t, qx, qy, qz, qw].
Vector6d log() const
Computes the logarithmic map (SE3 -> 6D tangent vector).
const Vector3< g_type > & translation() const
Returns a const reference to the translation vector.
SE3Quat(const Matrix3< g_type > &R, const Vector3< g_type > &t)
Constructs from a rotation matrix and translation vector.
Vector6d toMinimalVector() const
Converts to a minimal 6D vector [t, qx, qy, qz].
void setTranslation(const Vector3< g_type > &t_)
Sets the translation vector.
SE3Quat operator*(const SE3Quat &tr2) const
Composes two SE3 transforms: result = (*this) * tr2.
SE3Quat()
Default constructor.
SE3Quat(const MatrixBase< Derived > &v)
templaized constructor which allows v to be an arbitrary Eigen Vector type, e.g., Vector6d or Map<Vec...
static SE3Quat exp(const Vector6d &update)
Computes the exponential map from a 6D tangent vector to SE3.
Vector3< g_type > map(const Vector3< g_type > &xyz) const
Transforms a 3D point: R*xyz + t.
void fromMinimalVector(const Vector6d &v)
Initializes from a minimal 6D vector [t, qx, qy, qz], recovering qw.
SE3Quat & operator*=(const SE3Quat &tr2)
In-place composition with another SE3Quat.
void setRotation(const Quaternion< g_type > &r_)
Sets the rotation quaternion.
Eigen::Matrix< g_type, 6, 6 > adj() const
Computes the 6x6 adjoint matrix of this SE3 transform.
void fromVector(const Vector7d &v)
Initializes from a 7D vector [t, qw, qx, qy, qz].
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.
static constexpr t_float_type PI()
Returns the value of PI to a given precision.
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 tan(const Angle< t_type > &angle)
Performs optimized tangent operation on the given angle using pre-computed lookup table for optimal s...
Eigen::Matrix< g_type, 6, 1 > Vector6d
6D vector for the se(3) tangent space.
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...