Conventions¶
This page collects the conventions wuzp follows, with their sources. The design notes explain the decisions behind them.
Index placement¶
wuzp follows chapter 1 of Carroll's Lecture Notes on General Relativity, on which his book Spacetime and Geometry is based:
- An upper index is contravariant, e.g. the components
v^iof a vector, a lower index covariant, e.g. the componentsw_iof a covector (eqs. 1.30 to 1.39). - Vectors are stored as columns, covectors as rows (eq. 1.39).
- The first index of a tensor of rank 2 is the row of its matrix, the second the column, like
M^i_jin eq. 1.54. - A contraction pairs an upper with a lower index, and the order of the indices matters (eqs. 1.59 and 1.60):
innerProduct(lhs, rhs)contracts the last index oflhswith the first index ofrhs. - The pairing
w_i v^iof a covector and a vector needs no metric (eq. 1.35); the dot productg_ij v^i w^jdoes (eq. 1.55). - The inverse of a tensor of rank 2 maps the indices
(X, Y)to(not Y, not X), e.g.g_ijtog^ij, withg^ij g_jk = δ^i_k(eq. 1.56).
Transformation rules¶
For a linear transformation with component matrix A, i.e. contravariant components transform as v' = A v:
| Object | Indices | Rule |
|---|---|---|
| Vector | Indices<Up> |
v' = A v |
| Point | Indices<Up>, absolute |
p' = A p (via a relative intermediate) |
| Covector | Indices<Down> |
w' = w A^-1 |
| Linear map | Indices<Up, Down> |
T' = A T A^-1 |
| Bilinear form, e.g. a mass matrix | Indices<Down, Down> |
M' = A^-T M A^-1 |
| E.g. a covariance matrix | Indices<Up, Up> |
T' = A T A^T |
A^-1 appears twice in the rule for bilinear forms because A transforms components, so covariant indices transform with A^-1.
Equivalently, A^-1 is the change-of-basis matrix P of the Wikipedia article on change of basis ("old = P new").
The matrix A of a passive linear transformation maps the components of a vector in From to its components in To: its rows are the dual basis covectors of To, and the basis vectors of To are the columns of A^-1, all expressed in From (Carroll, eqs. 1.38 and 1.30).
Only for orthonormal bases, e.g. for a rotation, are the rows of A also the basis vectors of To.
A Jacobian J of a change of coordinates from From to To maps tangent objects, not points: transform() pushes vectors forward, v' = J v, and tensors with two upper indices, T' = J T J^T; pullback() pulls covectors back, w' = w J, and tensors with two lower indices, M' = J^T M J (Lee, Introduction to Smooth Manifolds, 2nd ed., Springer, 2013, chapters 3, 11 and 12).
Active and passive transformations¶
- An active transformation moves the objects expressed in its coordinate system.
- A passive transformation from
FromtoToexpresses the objects ofFrominTo, and only takes objects expressed inFrom(Active and passive transformation). PassiveTransformation<From = B, To = A>isX_ABin the monogram notation of Drake and^A_B Tin the notation of Craig (Introduction to Robotics, chapter 2): it maps the coordinates of a point inBto its coordinates inA.- Passive transformations compose like Drake's,
X_AB * X_BC = X_AC, i.e.^A_C T = ^A_B T ^B_C Tin the notation of Craig, and the coordinate systems that meet must match. - A motion and the change of coordinates to the coordinate system that it moves
Fromonto cancel each other: the passive rotation to the coordinate system rotated by an active rotationRhas the matrixR^T, the passive translation to the coordinate system translated bytthe vector-t, and the passive proper rigid transformation to the coordinate system moved by(R, t)the rotation and translation(R^T, -R^T t). - The parameters of a passive rotation, e.g. its quaternion, describe its own matrix, in the convention of robotics: those of
PassiveSpatialRotation<From = B, To = A>describeR_AB, the orientation ofBrelative toA, like Drake'sR_ABofq_AB, kindr'sC_IBofq_IBand Craig's^A_B R(see Rotations). The Lorentz boost keeps the convention of physics: its velocity is that ofTorelative toFrom(see Metrics and spacetime).
Translations and rigid transformations¶
- The vector of a passive translation is the vector from the origin of
Toto the origin ofFrom, expressed inTo, i.e. Drake'sp_AoBo_A. - A proper rigid transformation first rotates, then translates:
x -> R x + t. - In a passive proper rigid transformation, the rotation transforms from
Frominto an intermediate coordinate system with the origin ofFromand the axes ofTo, and the translation from there intoTo, so the translation is expressed inTo, like that of Drake's RigidTransformX_AB = (R_AB, p_AoBo_A). - Rigid transformations compose as
(R1, t1) * (R2, t2) = (R1 R2, R1 t2 + t1)and invert as(R, t)^-1 = (R^T, -R^T t)(Solà, Deray and Atchuthan, "A micro Lie theory for state estimation in robotics", eqs. 170 and 171). - Translations leave vectors, covectors and tensors with two upper indices unchanged, move points, and reject the other tensors, which may depend on the origin.
Rotations¶
The parameterizations, the manifold operations and the time derivatives of three-dimensional rotations (see Parameterizations of rotations):
- Quaternions follow Hamilton's convention,
ij = k, with the real part first,(w, x, y, z): the unit quaternionq = (cos(θ/2), sin(θ/2) n)rotates a vectorvintoq v q^*, by the right-handed angleθaround the axisn(Solà, "Quaternion kinematics for the error-state Kalman filter"), like Eigen, kindr, Drake and ROS, unlike the JPL convention. Its matrix is that of Eigen'sQuaternion::toRotationMatrix().toQuaternion()returns the unique quaternion, whose first element that is not zero is positive, like kindr'sgetUnique(), so its angle is in[0, π]. - Angle-axis and rotation vectors are right-handed, with the angle in
[0, π]when converted from a rotation; the rotation vector is the angle times the unit axis. - Euler angles are intrinsic: ZYX
(yaw, pitch, roll)isR = R_z(yaw) R_y(pitch) R_x(roll), i.e. aroundz, then the newy, then the newestx, and XYZ(a0, a1, a2)isR = R_x(a0) R_y(a1) R_z(a2), the extrinsic rotations in the opposite order. Converted from a rotation, the first and the last angle are in[-π, π)and the second in[-π/2, π/2], like kindr'sgetUnique(); at the gimbal lock, a second angle of±π/2, only the sum or the difference of the others is defined. - The parameters of a passive rotation describe its own matrix, in the convention of robotics: the parameters of
PassiveSpatialRotation<From = B, To = A>, e.g. the quaternionq_AB, give its matrixR_AB = R(q_AB), which maps the coordinates inBto those inA, the orientation ofBrelative toA, like Drake'sRotationMatrixR_ABofq_AB(monogram notation), kindr'sC_IBofq_IBand Craig's^A_B R(Introduction to Robotics, chapter 2). An active and a passive rotation with the same parameters have the same matrix. - The exponential and the logarithmic map of SO(3) are
fromRotationVector()andtoRotationVector(). - boxPlus and boxMinus perturb on the left,
R (+) v = Exp(v) RandR (-) S = Log(R S^T), the left plus and minus of Solà, Deray and Atchuthan, "A micro Lie theory for state estimation in robotics" (eqs. 27 and 28), with the increment in the coordinate system of an active rotation, or inToof a passive rotation, which equalsR Exp(v')for the same vectorv'expressed inFrom. - The Jacobian of the exponential map is the left Jacobian of SO(3),
J(v) = I + (1 - cos|v|) / |v|^2 [v]x + (|v| - sin|v|) / |v|^3 [v]x^2, so thatExp(v + dv) = Exp(J dv) Exp(v)to first order (Solà et al., eq. 145); for a rotation vector of a passive rotation expressed inFrom, it is the right JacobianJ(-v) = J(v)^T, so thatExp(v + dv) = Exp(v) Exp(J dv)(eq. 143). - Angular velocities
ware defined bydR/dt = [w]x R, for an active rotation expressed in its coordinate system; for a passive rotation,wis the angular velocity ofFromrelative toTo, expressed inTo, anddR/dt = R [w']xfor the same vectorw'expressed inFrom. The derivative of a quaternion isdq/dt = (0, w) q / 2 = q (0, w') / 2. - The skew-symmetric matrix of a vector is
[v]x = [[0, -v_z, v_y], [v_z, 0, -v_x], [-v_y, v_x, 0]], with[v]x w = v x w. - The pseudo-inverse is the Moore-Penrose pseudo-inverse of a matrix of full rank,
A^T (A A^T)^-1with fewer rows than columns and(A^T A)^-1 A^Twith more.
Comparison with kindr¶
kindr 1.2, whose conventions the tests check (tests/src/KindrConventions.cpp), has passive rotations and Hamilton quaternions since its 1.0 (see its cheat sheet).
Its rotation C_IB maps the coordinates of a vector in B to those in I, I_r = C_IB B_r, and its parameters, e.g. the quaternion q_IB, are those of the matrix C_IB, like those of wuzp: C_IB is PassiveSpatialRotation<From = B, To = I> with the same parameters.
| Topic | kindr | wuzp |
|---|---|---|
| Rotation | C_IB, C_IB.rotate(B_r) is I_r, inverseRotate() the inverse |
PassiveSpatialRotation<B, I>, X_IB in Drake's notation: its transform() and the transform() of its inverse() |
| Parameters | RotationQuaternion(w, x, y, z) q_IB, AngleAxis, RotationVector, EulerAnglesZyx(yaw, pitch, roll), EulerAnglesXyz(roll, pitch, yaw) |
fromQuaternion((w, x, y, z)), fromAngleAxis(), fromRotationVector() (axis and vector in I, where their components are those in B), fromEulerAnglesZyx((yaw, pitch, roll)), fromEulerAnglesXyz((roll, pitch, yaw)): the same matrix |
| Active rotations | none | ActiveSpatialRotation with the same parameters has the same matrix |
| Composition | C_IB * C_BC = C_IC |
X_IB * X_BC = X_IC, with the same parameters |
| Unique parameters | getUnique() of a quaternion and of Euler angles, with the angles in [-π, π), [-π/2, π/2) and [-π, π) |
toQuaternion() and toEulerAngles...() return them, with the second angle in [-π/2, π/2]; kindr's conversion into Euler angles returns the yaw in [0, π] (Eigen's eulerAngles()), until getUnique(). Within 1e-3 of the gimbal lock, kindr's getUnique() moves the yaw into the roll (ZYX) or the third angle into the first (XYZ), which changes the rotation; wuzp keeps the rotation, with the first angle 0 at an exact gimbal lock |
| Exponential and logarithmic map | exponentialMap(v), logarithmicMap() |
fromRotationVector(v), toRotationVector() |
| boxPlus, boxMinus | C.boxPlus(I_v) = Exp(I_v) C, C1.boxMinus(C2) = Log(C1 C2^-1) in I |
boxPlus(v) with v in I (To), or the same vector in B (From), e.g. boxPlus(B_w_IB * dt); boxMinus() in I, boxMinus<B>() in B |
| Jacobian of the exponential map | getJacobianOfExponentialMap(v) |
exponentialMapJacobian(v), the left Jacobian |
| Angle between rotations | getDisparityAngle() |
angularDistance() |
| Rotation between two vectors | C_IB.setFromVectors(B_v, I_v), I_v = C_IB B_v |
PassiveSpatialRotation<B, I>::fromTwoVectors(B_v, I_v) |
| Angular velocities | LocalAngularVelocity B_w_IB, GlobalAngularVelocity I_w_IB |
The angular velocity of B relative to I, expressed in B (From) or I (To), which the coordinate system of the vector tells apart |
| Derivatives | RotationQuaternionDiff, RotationMatrixDiff, EulerAnglesZyxDiff, EulerAnglesXyzDiff, and the angular velocities of them |
quaternionDerivative(), matrixDerivative(), eulerAnglesZyxDerivative(), eulerAnglesXyzDerivative(), and the angularVelocityFrom...(), in To by default; at the gimbal lock, kindr asserts, wuzp returns values that are not finite or arbitrarily large |
| Skew-symmetric matrix | getSkewMatrixFromVector(), getVectorFromSkewMatrix() |
skewSymmetricMatrix(), vectorOfSkewSymmetricMatrix(), which averages the elements of each pair |
| Pseudo-inverse | pseudoInverse(), by a singular value decomposition, also of lower rank |
pseudoInverse() of matrices of full rank, with checked units |
| Units | AngularVelocity and Torque are types of their own |
Angles are dimensionless, so an angular velocity is in 1/s and a torque in N m |
| Twists and wrenches | Twist and Wrench, the linear part first |
SpatialVelocity and SpatialForce, the rotational part first, like Drake and Modern Robotics, with the frames and the point as types (see Spatial vectors) |
Comparison with Eigen¶
The tests compare with Eigen's geometry module too (tests/src/EigenConventions.cpp), with every value matrix backend; tf2 and Drake are not in the dev containers, so their conventions are not tested.
| Eigen | wuzp |
|---|---|
Quaternion(w, x, y, z), stored as (x, y, z, w) in coeffs() |
QuaternionT{w, x, y, z} |
q.toRotationMatrix(), q * v |
the matrix and transform() of fromQuaternion(q), of an active and of a passive rotation |
AngleAxis(angle, axis) |
fromAngleAxis(angle, axis) |
AngleAxis(z) * AngleAxis(y) * AngleAxis(x), eulerAngles(2, 1, 0) with the first angle in [0, π], canonicalEulerAngles(2, 1, 0) (Eigen 5) |
fromEulerAnglesZyx(), toEulerAnglesZyx() with the ranges of canonicalEulerAngles() |
Quaternion::FromTwoVectors(a, b) |
fromTwoVectors(a, b) |
angularDistance() |
angularDistance() |
Spatial vectors¶
The spatial vectors follow Drake's spatial vectors and its monogram notation (see Spatial vectors):
SpatialVelocity<M, B, P, E>isV_MBp_E, the spatial velocity of the frameBmeasured inMabout the pointBp, expressed inE,SpatialAcceleration<M, B, P, E>isA_MBp_E, andSpatialForce<B, P, E>isF_Bp_E, the spatial force onBaboutBp. A point is the origin of a coordinate system, e.g.BoisB.- The rotational part comes first,
(ω, v),(α, a)and(τ, f), like Drake, Modern Robotics (Lynch and Park, Cambridge University Press, 2017, sections 3.3.2 and 3.4) and Featherstone, unlike kindr. - The shifts and compositions are those of Drake's
Shift(),ComposeWithMovingFrameVelocity()andComposeWithMovingFrameAcceleration():v_MBq = v_MBp + ω_MB × p_BpBq,a_MBq = a_MBp + α_MB × p_BpBq + ω_MB × (ω_MB × p_BpBq)andτ_Bq = τ_Bp - p_BpBq × f;ω_MC = ω_MB + ω_BC,v_MCq = v_MBp + ω_MB × p_BpCq + v_BCq,α_MC = α_MB + α_BC + ω_MB × ω_BCanda_MCq = a_MBp + α_MB × p_BpCq + ω_MB × (ω_MB × p_BpCq) + 2 ω_MB × v_BCq + a_BCq. The note of Drake'sComposeWithMovingFrameAcceleration()starts the last sum witha_BCoinstead ofa_MBo, a typo that its derivation corrects. - The spatial accelerations are Drake's, the derivatives of the velocities of points, not Featherstone's, the derivatives of the spatial velocities about a point fixed in
M, which differ from them byω × v. X_AB.transform(V_MBp_B)isV_MBp_A, rotated byR_ABabout the same point, like a vector.- The adjoint map of the passive proper rigid transformation
X_AB = (R_AB, p_AoBo_A)is[Ad_T] = [[R, 0], [[p] R, R]]for twists about the origin ofB, expressed inB,V_s = [Ad_T_sb] V_bin Modern Robotics, and its transposed inverse for wrenches,F_s = [Ad_T_bs]^T F_b:ω' = R ω,v' = R v + p × (R ω),f' = R fandτ' = R τ + p × (R f), i.e.X_AB.transform(V).shift<A>(-p_AoBo_A). - The angular velocity of
PassiveSpatialRotation<From = B, To = A>is the rotational part ofSpatialVelocity<A, B, P, E>, expressed inE = AorE = B.
Metrics and spacetime¶
- The default metric of a coordinate system is Euclidean, the identity of orthonormal axes, where a vector and the covector it lowers to have the same components (Carroll, after eq. 1.62).
Minkowskiisη = diag(1, -1, ..., -1), with the signature(+, -, ..., -)and the time component first, in length units (x^0 = c t). Carroll uses the signature(-, +, +, +), whose metric is-η; both give the same Lorentz transformations, defined byη = Λ^T η Λ(eq. 1.14).- The passive Lorentz boost has the standard form with
Λ_0i = -γ β_i, for the velocity ofTorelative toFrom, expressed inFrom, in the convention of physics, unlike the parameters of passive rotations, which describeFromrelative toTo(see Rotations). - The inverse of a Lorentz transformation is
η Λ^T η, which follows fromη = Λ^T η Λ; that of a rotation isR^T.
Units¶
- Angles are dimensionless, with every units backend, like the SI treats them (SI Brochure, 9th edition, section 2.3.3).
- The units of a matrix that describes a linear map have the form
M_ij = a_i / b_j, and those of its inverse are(M^-1)_ij = b_i / a_j(Hart, Multidimensional Analysis, 1995, sections 3.1 and 3.3). - The units of a Jacobian are
[x_i] / [q_j]for the coordinatesqofFromandxofTo.
Comparisons¶
isApprox(other, precision) compares relatively, like Eigen's isApprox: ||a - b|| <= p min(||a||, ||b||), in the Frobenius norm of the values.
Integer values compare exactly, whatever the precision, like with Eigen: the squares of their differences would overflow.
It cannot compare with zero, and for points it depends on the origin (see Limitations).