#include <Transform.h>
A frame is an orthogonal, right-handed set of three axes, and an origin point. A transform X from frame B to F consists of 3 perpendicular unit vectors defining F's axes as viewed from B (that is, as expressed in the basis formed by B's axes), and a vector from B's origin point OB to F's origin point OF. Note that the meaning of "B" comes from the context in which the transform is used. We use the phrase "frame F is in frame B" to describe the above relationship, that is, "in" means both measured from and expressed in.
The axis vectors constitute a Rotation. They are ordered 1-2-3 or x-y-z as you prefer, with z = x X y, making a right-handed set. These axes are arranged as columns of a 3x3 rotation matrix R_BF = [ x y z ] which is a direction cosine (rotation) matrix useful for conversions between frame B and F. (The columns of R_BF are F's coordinate axes, expressed in B.) For example, given a vector vF expressed in the F frame, that same vector re-expressed in B is given by vB = R_BF*vF. F's origin point OF is stored as the translation vector T_BF=(OF-OB) and expressed in B.
Transform is designed to behave as much as possible like the computer graphics 4x4 transform X which would be arranged like this:
* * [ | ] * X = [ R | T ] R is a 3x3 orthogonal rotation matrix * [.......|...] T os a 3x1 translation vector * [ 0 0 0 1 ] * *
These can be composed directly by matrix multiplication, but more importantly they have a particularly simple inverse:
* * -1 [ | ] * X = [ ~R | T* ] ~R is R transpose, T* = ~R(-T). * [.......|....] * [ 0 0 0 1 ] * *
This inverse is so simple that we compute it simply by defining another type, InverseTransform, which is identical to Transform in memory but behaves as though it contains the inverse. That way we invert just by changing point of view (recasting) rather than computing.
This is a "POD" (plain old data) class with a well-defined memory layout on which a client of this class may depend: There are exactly 4 consecutive, packed 3-vectors in the order x,y,z,T. That is, this class is equivalent to an array of 12 Reals with the order x1,x2,x3,y1,y2,y3,z1,z2,z3,T1,T2,T3. It is expressly allowed to reinterpret Transform objects in any appropriate manner that depends on this memory layout.
Public Member Functions | |
Transform () | |
Default constructor gives an identity transform. | |
Transform (const Rotation &R, const Vec3 &T) | |
Combine a rotation and a translation into a transform. | |
Transform (const Rotation &R) | |
Construct or default-convert a rotation into a transform containing that rotation and zero translation. | |
Transform (const Vec3 &T) | |
Construct or default-convert a translation (expressed as a Vec3) into a transform with that translation and a zero rotation. | |
Transform & | operator= (const InverseTransform &X) |
Assignment from InverseTransform. | |
Transform & | set (const Rotation &R, const Vec3 &T) |
Assign a new value to this transform, explicitly providing the rotation and translation separately. | |
Transform & | setToZero () |
By zero we mean "zero transform", i.e., an identity rotation and zero translation. | |
Transform & | setToNaN () |
This fills both the rotation and translation with NaNs. | |
const InverseTransform & | invert () const |
Return a read-only inverse of the current Transform, simply by casting it to the InverseTransform type. | |
InverseTransform & | updInvert () |
Return a writable (lvalue) inverse of the current transform, simply by casting it to the InverseTransform type. | |
const InverseTransform & | operator~ () const |
Overload transpose operator to mean inversion. | |
InverseTransform & | operator~ () |
Overload transpose operator to mean inversion. | |
Transform | compose (const Transform &X_FY) const |
Compose the current transform (X_BF) with the given one. | |
Transform | compose (const InverseTransform &X_FY) const |
Compose the current transform (X_BF) with one that is supplied as an InverseTransform (typically as a result of applying the "~" operator to a transform). | |
Vec3 | xformFrameVecToBase (const Vec3 &vF) const |
Transform a vector expressed in our "F" frame to our "B" frame. | |
Vec3 | xformBaseVecToFrame (const Vec3 &vB) const |
Transform a vector expressed in our "B" frame to our "F" frame. | |
Vec3 | shiftFrameStationToBase (const Vec3 &sF) const |
Transform a point (station) measured from and expressed in our "F" frame to that same point but measured from and expressed in our "B" frame. | |
Vec3 | shiftBaseStationToFrame (const Vec3 &sB) const |
Transform a point (station) measured from and expressed in our "B" frame to that same point but measured from and expressed in our "F" frame. | |
const Rotation & | R () const |
Return a read-only reference to the contained rotation R_BF. | |
Rotation & | updR () |
Return a writable (lvalue) reference to the contained rotation R_BF. | |
const Rotation::ColType & | x () const |
Return a read-only reference to the x direction (unit vector) of the F frame, expressed in the B frame. | |
const Rotation::ColType & | y () const |
Return a read-only reference to the y direction (unit vector) of the F frame, expressed in the B frame. | |
const Rotation::ColType & | z () const |
Return a read-only reference to the z direction (unit vector) of the F frame, expressed in the B frame. | |
const InverseRotation & | RInv () const |
Return a read-only reference to the inverse (transpose) of our contained rotation, that is R_FB. | |
InverseRotation & | updRInv () |
Return a writable (lvalue) reference to the inverse (transpose) of our contained rotation, that is R_FB. | |
const Vec3 & | T () const |
Return a read-only reference to our translation vector T_BF. | |
Vec3 & | updT () |
Return a writable (lvalue) reference to our translation vector T_BF. | |
Transform & | setT (const Vec3 &T) |
Assign a new value to our translation vector. | |
Vec3 | TInv () const |
Calculate the inverse of the translation vector in this transform. | |
Transform & | setTInv (const Vec3 &T_FB) |
Assign a value to the inverse of our translation vector. | |
const Mat34 & | asMat34 () const |
Recast this transform as a read-only 3x4 matrix. | |
Mat34 | toMat34 () const |
Less efficient version of asMat34(); copies into return variable. | |
Mat44 | toMat44 () const |
Return the equivalent 4x4 transformation matrix. |
Transform | ( | ) | [inline] |
Combine a rotation and a translation into a transform.
Construct or default-convert a rotation into a transform containing that rotation and zero translation.
Construct or default-convert a translation (expressed as a Vec3) into a transform with that translation and a zero rotation.
Transform & operator= | ( | const InverseTransform & | X | ) | [inline] |
Assignment from InverseTransform.
This means that the transform we're assigning to must end up with the same meaning as the inverse transform X has, so we'll need to end up with:
References InverseTransform::R(), and InverseTransform::T().
Assign a new value to this transform, explicitly providing the rotation and translation separately.
We return a reference to the now-modified transform as though this were an assignment operator.
References Transform::R(), and Transform::T().
Transform& setToZero | ( | ) | [inline] |
By zero we mean "zero transform", i.e., an identity rotation and zero translation.
We return a reference to the now-modified transform as though this were an assignment operator.
References Rotation::setRotationToIdentityMatrix().
Transform& setToNaN | ( | ) | [inline] |
This fills both the rotation and translation with NaNs.
Note: this is not the same as a default-constructed transform, which is a legitimate identity transform instead. We return a reference to the now-modified transform as though this were an assignment operator.
References Rotation::setRotationToNaN(), and Vec::setToNaN().
const InverseTransform& invert | ( | ) | const [inline] |
Return a read-only inverse of the current Transform, simply by casting it to the InverseTransform type.
Zero cost.
Referenced by Transform::operator~().
InverseTransform& updInvert | ( | ) | [inline] |
Return a writable (lvalue) inverse of the current transform, simply by casting it to the InverseTransform type.
That is, this is an lvalue. Zero cost.
Referenced by Transform::operator~().
const InverseTransform& operator~ | ( | ) | const [inline] |
InverseTransform& operator~ | ( | ) | [inline] |
Overload transpose operator to mean inversion.
References Transform::updInvert().
Compose the current transform (X_BF) with the given one.
That is, return X_BY=X_BF*X_FY. Cost is 63 flops.
References Transform::R(), Transform::T(), and Transform::Transform().
Referenced by SimTK::operator*().
Transform compose | ( | const InverseTransform & | X_FY | ) | const [inline] |
Compose the current transform (X_BF) with one that is supplied as an InverseTransform (typically as a result of applying the "~" operator to a transform).
That is, return X_BY=X_BF*X_FY, but now X_FY is represented as ~X_YF. Cost is an extra 18 flops to calculate X_FY.T(), total 81 flops.
References InverseTransform::R(), InverseTransform::T(), and Transform::Transform().
Transform a vector expressed in our "F" frame to our "B" frame.
Note that this involves rotation only; it is independent of the translation stored in this transform. Cost is 15 flops.
Referenced by Transform::shiftFrameStationToBase().
Transform a vector expressed in our "B" frame to our "F" frame.
Note that this involves rotation only; it is independent of the translation stored in this transform. Cost is 15 flops.
Referenced by Transform::shiftBaseStationToFrame().
Transform a point (station) measured from and expressed in our "F" frame to that same point but measured from and expressed in our "B" frame.
Cost is 18 flops.
References Transform::xformFrameVecToBase().
Referenced by SimTK::operator*().
Transform a point (station) measured from and expressed in our "B" frame to that same point but measured from and expressed in our "F" frame.
Cost is 18 flops.
References Transform::xformBaseVecToFrame().
const Rotation& R | ( | ) | const [inline] |
Return a read-only reference to the contained rotation R_BF.
Referenced by InverseTransform::compose(), Transform::compose(), MobilizedBody::findBodyAccelerationInAnotherBody(), MobilizedBody::findBodyVelocityInAnotherBody(), MobilizedBody::getBodyRotation(), SimTK::operator==(), Transform::set(), Transform::x(), Transform::y(), and Transform::z().
Rotation& updR | ( | ) | [inline] |
Return a writable (lvalue) reference to the contained rotation R_BF.
const Rotation::ColType& x | ( | ) | const [inline] |
Return a read-only reference to the x direction (unit vector) of the F frame, expressed in the B frame.
References Transform::R(), and Rotation::x().
const Rotation::ColType& y | ( | ) | const [inline] |
Return a read-only reference to the y direction (unit vector) of the F frame, expressed in the B frame.
References Transform::R(), and Rotation::y().
const Rotation::ColType& z | ( | ) | const [inline] |
Return a read-only reference to the z direction (unit vector) of the F frame, expressed in the B frame.
References Transform::R(), and Rotation::z().
const InverseRotation& RInv | ( | ) | const [inline] |
Return a read-only reference to the inverse (transpose) of our contained rotation, that is R_FB.
Referenced by InverseTransform::operator=().
InverseRotation& updRInv | ( | ) | [inline] |
Return a writable (lvalue) reference to the inverse (transpose) of our contained rotation, that is R_FB.
const Vec3& T | ( | ) | const [inline] |
Return a read-only reference to our translation vector T_BF.
Referenced by InverseTransform::compose(), Transform::compose(), MobilizedBody::findBodyAccelerationInAnotherBody(), MobilizedBody::findBodyVelocityInAnotherBody(), MobilizedBody::getBodyOriginLocation(), SimTK::operator==(), and Transform::set().
Vec3& updT | ( | ) | [inline] |
Return a writable (lvalue) reference to our translation vector T_BF.
Caution: if you write through this reference you update the transform.
Assign a new value to our translation vector.
We expect the supplied vector T
to be expressed in our B frame. A reference to the now-modified transform is returned as though this were an assignment operator.
Vec3 TInv | ( | ) | const [inline] |
Calculate the inverse of the translation vector in this transform.
The returned vector will be the negative of the original and will be expressed in the F frame rather than our B frame. Cost is 18 flops.
Referenced by InverseTransform::operator=().
Assign a value to the inverse of our translation vector.
That is, we're given a vector in F which we invert and reexpress in B to store it in T, so that we get the original argument back if we ask for the inverse of T. Sorry, can't update TInv as an lvalue, but here we want -(~R_BF*T_BF)=T_FB => T_BF=-(R_BF*T_FB) so we can calculate it in 18 flops. A reference to the now-modified transform is returned as though this were an assignment operator.
const Mat34& asMat34 | ( | ) | const [inline] |
Recast this transform as a read-only 3x4 matrix.
This is a zero-cost reinterpretation of the data; the first three columns are the columns of the rotation and the last column is the translation.
References Mat::getAs().
Referenced by Transform::toMat34(), and Transform::toMat44().
Mat34 toMat34 | ( | ) | const [inline] |
Mat44 toMat44 | ( | ) | const [inline] |
Return the equivalent 4x4 transformation matrix.
References Transform::asMat34(), and Mat::updSubMat().