Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
momentum::TransformT< T > Struct Template Reference

Lightweight transform with separate rotation, translation, and uniform scaling. More...

#include <transform.h>

Public Member Functions

 TransformT ()
 Creates the identity transform (zero translation, identity rotation, unit scale).
template<typename T2>
 TransformT (const TransformT< T2 > &other)
 TransformT (const Vector3< T > &translation_in, const Quaternion< T > &rotation_in=Quaternion< T >::Identity(), const T &scale_in=T(1))
 TransformT (Vector3< T > &&translation_in, Quaternion< T > &&rotation_in=Quaternion< T >::Identity(), T &&scale_in=T(1))
 TransformT (const Affine3< T > &other)
 TransformT (const Matrix4< T > &other)
TransformT< T > & operator= (const Affine3< T > &other)
TransformT< T > & operator= (const Matrix4< T > &other)
TransformT< T > operator* (const TransformT< T > &other) const
 Composes transforms: (*this) * other applies other first, then *this.
Affine3< T > operator* (const Affine3< T > &other) const
 Composes with an Affine3.
Vector3< T > operator* (const Vector3< T > &other) const
 operator Affine3< T > () const
Affine3< T > toAffine3 () const
Matrix4< T > toMatrix () const
 Returns the equivalent 4x4 homogeneous matrix [s*R | t; 0 0 0 1].
Matrix3< T > toRotationMatrix () const
 Returns the rotation as a 3x3 orthogonal matrix (scale not included).
Matrix3< T > toLinear () const
 Returns scale * R, the linear part of the transform.
Vector3< T > getAxisX () const
 Returns the rotated unit-X axis (i.e.
Vector3< T > transformPoint (const Vector3< T > &pt) const
 Applies the full transform to a point: translation + rotation * (scale * pt).
Vector3< T > rotate (const Vector3< T > &vec) const
 Applies only the rotation to a direction vector (translation and scale are ignored).
TransformT< T > inverse () const
 Returns the inverse transform such that (*this) * inverse() == identity.
template<typename T2>
TransformT< T2 > cast () const
bool isApprox (const TransformT< T > &other, T tol=Eigen::NumTraits< T >::dummy_precision()) const
 Approximate equality test using tol as a relative precision.

Static Public Member Functions

static TransformT< T > makeRotation (const Quaternion< T > &rotation_in)
 Creates a transform with the given rotation, identity translation, and unit scale.
static TransformT< T > makeTranslation (const Vector3< T > &translation_in)
 Creates a transform with the given translation, identity rotation, and unit scale.
static TransformT< T > makeScale (const T &scale_in)
 Creates a transform with the given scale, identity rotation, and zero translation.
static TransformT< T > makeRandom (bool translation=true, bool rotation=true, bool scale=true)
 Creates a random transform.
static TransformT< T > fromAffine3 (const Affine3< T > &other)
 Decomposes an Eigen::Affine3 into rotation, translation, and uniform scale.
static TransformT< T > fromMatrix (const Matrix4< T > &other)
 Decomposes a 4x4 homogeneous matrix into rotation, translation, and uniform scale.

Public Attributes

Quaternion< T > rotation
 Unit quaternion encoding the rotation.
Vector3< T > translation
T scale
 Uniform scale factor applied before rotation and translation.

Detailed Description

template<typename T>
struct momentum::TransformT< T >

Lightweight transform with separate rotation, translation, and uniform scaling.

Applied to a point as: p' = translation + rotation * (scale * p).

Template Parameters
TThe scalar type (float or double).
Design rationale
TransformT stores rotation (quaternion), translation, and uniform scale separately instead of as a 4x4 matrix. Preferred over Eigen::Affine3 throughout Momentum because:
  • Composition is faster: quaternion multiply + scaled translation is cheaper than 4x4 matrix multiply for uniform-scale transforms.
  • Decomposition is free: extracting rotation, translation, or scale is a field access, not a matrix decomposition.
  • FK derivatives are simpler: the Jacobian of rotation, translation, and scale are computed independently (see JointStateT).

Use Eigen::Affine3 only at IO boundaries (FBX, glTF) where the format stores 4x4 matrices. Convert via TransformT::fromAffine3() / toAffine3().

Definition at line 36 of file transform.h.

Constructor & Destructor Documentation

◆ TransformT() [1/6]

template<typename T>
momentum::TransformT< T >::TransformT ( )
inline

Creates the identity transform (zero translation, identity rotation, unit scale).

Definition at line 74 of file transform.h.

Referenced by momentum::TransformT< float >::cast(), fromAffine3(), fromMatrix(), inverse(), makeRandom(), makeRotation(), makeScale(), makeTranslation(), and momentum::TransformT< float >::operator*().

◆ TransformT() [2/6]

template<typename T>
template<typename T2>
momentum::TransformT< T >::TransformT ( const TransformT< T2 > & other)
inlineexplicit
Template Parameters
T2Source scalar type.

Definition at line 78 of file transform.h.

◆ TransformT() [3/6]

template<typename T>
momentum::TransformT< T >::TransformT ( const Vector3< T > & translation_in,
const Quaternion< T > & rotation_in = Quaternion<T>::Identity(),
const T & scale_in = T(1) )
inlineexplicit

Definition at line 83 of file transform.h.

◆ TransformT() [4/6]

template<typename T>
momentum::TransformT< T >::TransformT ( Vector3< T > && translation_in,
Quaternion< T > && rotation_in = Quaternion<T>::Identity(),
T && scale_in = T(1) )
inlineexplicit

Definition at line 89 of file transform.h.

◆ TransformT() [5/6]

template<typename T>
momentum::TransformT< T >::TransformT ( const Affine3< T > & other)
inlineexplicit
See also
fromAffine3 for preconditions.

Definition at line 98 of file transform.h.

◆ TransformT() [6/6]

template<typename T>
momentum::TransformT< T >::TransformT ( const Matrix4< T > & other)
inlineexplicit
See also
fromMatrix for preconditions.

Definition at line 103 of file transform.h.

Member Function Documentation

◆ cast()

template<typename T>
template<typename T2>
TransformT< T2 > momentum::TransformT< T >::cast ( ) const
inlinenodiscard
Template Parameters
T2Target scalar type.

Definition at line 206 of file transform.h.

Referenced by momentum::CollisionGeometryStateT< T >::updatePrimitive().

◆ fromAffine3()

template<typename T>
TransformT< T > momentum::TransformT< T >::fromAffine3 ( const Affine3< T > & other)
staticnodiscard

Decomposes an Eigen::Affine3 into rotation, translation, and uniform scale.

Precondition
other.linear() is a uniformly scaled rotation (no shear, isotropic scale); the result is undefined for general affine transforms.

Definition at line 55 of file transform.cpp.

References fromMatrix(), and TransformT().

Referenced by momentum::TransformT< float >::operator=(), and momentum::TransformT< float >::TransformT().

◆ fromMatrix()

template<typename T>
TransformT< T > momentum::TransformT< T >::fromMatrix ( const Matrix4< T > & other)
staticnodiscard

Decomposes a 4x4 homogeneous matrix into rotation, translation, and uniform scale.

Precondition
The upper-left 3x3 block is a uniformly scaled rotation and the bottom row is [0 0 0 1]; the result is undefined otherwise.

Definition at line 60 of file transform.cpp.

References TransformT().

Referenced by fromAffine3(), momentum::TransformT< float >::operator=(), and momentum::TransformT< float >::TransformT().

◆ getAxisX()

template<typename T>
Vector3< T > momentum::TransformT< T >::getAxisX ( ) const
inlinenodiscard

Returns the rotated unit-X axis (i.e.

the first column of the rotation matrix). Inlined hand-expansion of Eigen::Quaternion::toRotationMatrix() for the X column; faster than constructing the full 3x3 matrix when only one axis is needed.

Precondition
rotation is a unit quaternion; otherwise the returned vector is scaled.

Definition at line 173 of file transform.h.

Referenced by momentum::CollisionGeometryStateT< T >::updatePrimitive().

◆ inverse()

template<typename T>
TransformT< T > momentum::TransformT< T >::inverse ( ) const
nodiscard

Returns the inverse transform such that (*this) * inverse() == identity.

Precondition
scale != 0.

Definition at line 93 of file transform.cpp.

References rotation, scale, TransformT(), and translation.

Referenced by momentum::skeletonStateToJointParameters(), momentum::skeletonStateToJointParametersRespectingActiveParameters(), and momentum::transformAtoB().

◆ isApprox()

template<typename T>
bool momentum::TransformT< T >::isApprox ( const TransformT< T > & other,
T tol = Eigen::NumTraits<T>::dummy_precision() ) const
inlinenodiscard

Approximate equality test using tol as a relative precision.

Currently routed through the Affine3 representation; this conflates rotation, translation, and scale tolerances.

Definition at line 218 of file transform.h.

◆ makeRandom()

template<typename T>
TransformT< T > momentum::TransformT< T >::makeRandom ( bool translation = true,
bool rotation = true,
bool scale = true )
staticnodiscard

Creates a random transform.

Parameters
[in]translationIf true, sample translation uniformly in [-1, 1] per axis; otherwise zero.
[in]rotationIf true, sample a uniformly random unit quaternion; otherwise identity.
[in]scaleIf true, sample scale uniformly in [0.5, 2.0]; otherwise 1.

Definition at line 36 of file transform.cpp.

References rotation, scale, TransformT(), and translation.

◆ makeRotation()

template<typename T>
TransformT< T > momentum::TransformT< T >::makeRotation ( const Quaternion< T > & rotation_in)
staticnodiscard

Creates a transform with the given rotation, identity translation, and unit scale.

Definition at line 21 of file transform.cpp.

References TransformT().

◆ makeScale()

template<typename T>
TransformT< T > momentum::TransformT< T >::makeScale ( const T & scale_in)
staticnodiscard

Creates a transform with the given scale, identity rotation, and zero translation.

Definition at line 31 of file transform.cpp.

References TransformT().

◆ makeTranslation()

template<typename T>
TransformT< T > momentum::TransformT< T >::makeTranslation ( const Vector3< T > & translation_in)
staticnodiscard

Creates a transform with the given translation, identity rotation, and unit scale.

Definition at line 26 of file transform.cpp.

References TransformT().

◆ operator Affine3< T >()

template<typename T>
momentum::TransformT< T >::operator Affine3< T > ( ) const
inlineexplicit

Definition at line 144 of file transform.h.

◆ operator*() [1/3]

template<typename T>
Affine3< T > momentum::TransformT< T >::operator* ( const Affine3< T > & other) const
inlinenodiscard

Composes with an Affine3.

The result is a general Affine3 because other may contain shear or non-uniform scale that cannot be represented by a TransformT.

Definition at line 133 of file transform.h.

◆ operator*() [2/3]

template<typename T>
TransformT< T > momentum::TransformT< T >::operator* ( const TransformT< T > & other) const
inlinenodiscard

Composes transforms: (*this) * other applies other first, then *this.

Equivalent to multiplying the homogeneous matrices: [ s_1*R_1 t_1 ] * [ s_2*R_2 t_2 ] = [ s_1*s_2*R_1*R_2 s_1*R_1*t_2 + t_1 ] [ 0 1 ] [ 0 1 ] [ 0 1 ]

Definition at line 124 of file transform.h.

◆ operator*() [3/3]

template<typename T>
Vector3< T > momentum::TransformT< T >::operator* ( const Vector3< T > & other) const
inlinenodiscard

Definition at line 140 of file transform.h.

◆ operator=() [1/2]

template<typename T>
TransformT< T > & momentum::TransformT< T >::operator= ( const Affine3< T > & other)
inline
See also
fromAffine3 for preconditions.

Definition at line 108 of file transform.h.

◆ operator=() [2/2]

template<typename T>
TransformT< T > & momentum::TransformT< T >::operator= ( const Matrix4< T > & other)
inline
See also
fromMatrix for preconditions.

Definition at line 114 of file transform.h.

◆ rotate()

template<typename T>
Vector3< T > momentum::TransformT< T >::rotate ( const Vector3< T > & vec) const
nodiscard

Applies only the rotation to a direction vector (translation and scale are ignored).

Definition at line 88 of file transform.cpp.

References rotation.

◆ toAffine3()

template<typename T>
Affine3< T > momentum::TransformT< T >::toAffine3 ( ) const
nodiscard

◆ toLinear()

template<typename T>
Matrix3< T > momentum::TransformT< T >::toLinear ( ) const
inlinenodiscard

Returns scale * R, the linear part of the transform.

Definition at line 165 of file transform.h.

Referenced by momentum::operator*(), and momentum::TransformT< float >::operator*().

◆ toMatrix()

template<typename T>
Matrix4< T > momentum::TransformT< T >::toMatrix ( ) const
inlinenodiscard

Returns the equivalent 4x4 homogeneous matrix [s*R | t; 0 0 0 1].

Definition at line 151 of file transform.h.

◆ toRotationMatrix()

template<typename T>
Matrix3< T > momentum::TransformT< T >::toRotationMatrix ( ) const
inlinenodiscard

◆ transformPoint()

template<typename T>
Vector3< T > momentum::TransformT< T >::transformPoint ( const Vector3< T > & pt) const
inlinenodiscard

Applies the full transform to a point: translation + rotation * (scale * pt).

Definition at line 193 of file transform.h.

Referenced by momentum::TransformT< float >::operator*().

Member Data Documentation

◆ rotation

◆ scale

◆ translation


The documentation for this struct was generated from the following files: