maspack.matrix
Class RigidTransform3d

java.lang.Object
  extended bymaspack.matrix.MatrixObject
      extended bymaspack.matrix.AffineTransform3dObject
          extended bymaspack.matrix.RigidTransform3d
All Implemented Interfaces:
java.io.Serializable

public class RigidTransform3d
extends AffineTransform3dObject

A specialized 4 x 4 matrix that implements a three-dimensional rigid body transformation in homogeneous coordinates.

A rigid body transformation is used to transform a point from one spatial coordinate frame into another. If x0 and x1 denote the point in the orginal frame 0 and target frame 1, respectively, then the transformation is computed according to

 x1 = R x0 + p
 
where R is a 3 x 3 rotation matrix and p is a translation vector. In homogenous coordinates, this operation can be represented as
 [ x1 ]   [ R  p ] [ x0 ]
 [    ] = [      ] [    ]
 [  1 ]   [ 0  1 ] [  1 ]
 
The components p and R of the transformation represent the position and orientation of frame 0 with respect to frame 1. In particular, the translation vector p gives the origin position, while the columns of R give the directions of the axes.

If X01 is a transformation from frame 0 to frame 1, and X12 is a transformation from frame 1 to frame 2, then the transformation from frame 0 to frame 2 is given by the product

 X02 = X12 X01
 
In this way, a transformation can be created by multiplying a series of sub-transformations.

If X01 is a transformation from frame 0 to frame 1, then the inverse transformation X10 is a transformation from frame 1 to frame 0, and is given by

       [  T    T   ]
       [ R   -R  p ]
 X10 = [           ]
       [ 0     1   ]
 

In this class, the fields R and p are exposed, and users can manipulate them as desired. For example, specifying a rotation using Euler angles would be done using the setEuler method in R. This allows us to minimize the number of methds in the RigidTransform3d class itself.

Note that for reasons of efficiency, rigid transforms do not perform scaling. If you want scaling as well, then you should use an AffineTransform3d object, perhaps with a code fragment such as this:

    RigidTransform3d XR = RigidTransform3d();
    AffineTransform3d XA = new AffineTransform3d();
 
    XR.p.set (10, 20, 30);        // for example
    XR.R.setRpy (Math.PI, 0, 0);
    XA.set (XR);                  
    XA.applyScaling (1, 2, 3);
 object

See Also:
Serialized Form

Field Summary
static int AXIS_ANGLE_STRING
          Specifies a string representation of this transformation as a 7-tuple consisting of a translation vector followed by a rotation axis and the corresponding angle (in degrees).
static int MATRIX_3X4_STRING
          Specifies a string representation of this transformation as a 3 x 4 matrix (i.e., with the 4th row ommitted).
static int MATRIX_4X4_STRING
          Specifies a string representation of this transformation as a 4 x 4 matrix.
 Vector3d p
          Translation vector associated with this transformation.
 RotationMatrix3d R
          Rotation matrix associated with this transformation.
 
Constructor Summary
RigidTransform3d()
          Creates a new transformation initialized to the identity.
RigidTransform3d(RigidTransform3d X)
          Creates a new transformation which is a copy of an existing one.
RigidTransform3d(Vector3d p, AxisAngle axisAng)
          Creates a new transformation with the specified translation vector and rotation.
RigidTransform3d(Vector3d p, RotationMatrix3d R)
          Creates a new transformation with the specified translation vector and rotation matrix.
 
Method Summary
 boolean invert()
          Inverts this transform in place.
 boolean invert(RigidTransform3d X)
          Inverts transform X and places the result in this transform.
static void main(java.lang.String[] args)
           
 void mul(RigidTransform3d X)
          Post-multiplies this transformation by another and places the result in this transformation.
 void mul(RigidTransform3d X1, RigidTransform3d X2)
          Multiplies transformation X1 by X2 and places the result in this transformation.
 void mulAxisAngle(AxisAngle axisAng)
          Post-multiplies this transformation by an implicit second transformation consisting of a pure rotation, expressed as an axis-angle, and places the result in this transformation.
 void mulAxisAngle(double ux, double uy, double uz, double ang)
          Post-multiplies this transformation by an implicit second transformation consisting of a pure rotation, expressed as an axis-angle, and places the result in this transformation.
 void mulEuler(double phi, double theta, double psi)
          Post-multiplies this transformation by an implicit second transformation consisting of a pure rotation, expressed by Euler angles, and places the result in this transformation.
 void mulInverse(RigidTransform3d X)
          Post-multiplies this transformation by the inverse of transformation X and places the result in this transformation.
 boolean mulInverse(Vector4d vr, Vector4d v1)
          Multiplies the column vector v1 by the inverse of this transform and places the result in vr.
 void mulInverseBoth(RigidTransform3d X1, RigidTransform3d X2)
          Multiplies the inverse of transformation X1 by the inverse of transformation X2 and places the result in this transformation.
 void mulInverseLeft(RigidTransform3d X1, RigidTransform3d X2)
          Multiplies the inverse of transformation X1 by transformation X2 and places the result in this transformation.
 void mulInverseRight(RigidTransform3d X1, RigidTransform3d X2)
          Multiplies transformation X1 by the inverse of transformation X2 and places the result in this transformation.
 void mulRotation(RotationMatrix3d R2)
          Post-multiplies this transformation by an implicit second transformation consisting of a pure rotation, and places the result in this transformation.
 void mulRotX(double ang)
          Post-multiplies this transformation by an implicit second transformation consisting of a pure rotation about the x axis, and places the result in this transformation.
 void mulRotY(double ang)
          Post-multiplies this transformation by an implicit second transformation consisting of a pure rotation about the y axis, and places the result in this transformation.
 void mulRotZ(double ang)
          Post-multiplies this transformation by an implicit second transformation consisting of a pure rotation about the z axis, and places the result in this transformation.
 void mulRpy(double roll, double pitch, double yaw)
          Post-multiplies this transformation by an implicit second transformation consisting of a pure rotation, expressed by roll-pitch-yaw angles, and places the result in this transformation.
 void mulXyz(double x, double y, double z)
          Post-multiplies this transformation by an implicit second transformation consisting of a pure translation, and places the result in this transformation.
 void scan(java.io.StreamTokenizer stok)
          Reads the contents of this transformation from a StreamTokenizer.
 java.lang.String toString()
          Returns a string representation of this transformation as a 4 x 4 matrix.
 java.lang.String toString(NumberFormat numberFmt, int outputCode)
          Returns a specified string representation of this transformation, with each number formatted according to the a supplied numeric format.
 java.lang.String toString(java.lang.String numberFmtStr)
          Returns a string representation of this transformation as a 4 x 4 matrix, with each number formatted according to a supplied numeric format.
 java.lang.String toString(java.lang.String numberFmtStr, int outputCode)
          Returns a specified string representation of this transformation, with each number formatted according to the a supplied numeric format.
 
Methods inherited from class maspack.matrix.AffineTransform3dObject
colSize, epsilonEquals, equals, get, get, getColumn, getMatrix, getOffset, getRow, mul, mul, mulInverse, rowSize, set, set, setColumn, setIdentity, setRotation, setRotation, setRotation, setRow, setTranslation
 
Methods inherited from class maspack.matrix.MatrixObject
determinant, epsilonEquals, equals, equals, frobeniusNorm, get, getColumn, getRow, infinityNorm, isFixedSize, oneNorm, set, set, setColumn, setRow, setSize, toString
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

AXIS_ANGLE_STRING

public static final int AXIS_ANGLE_STRING
Specifies a string representation of this transformation as a 7-tuple consisting of a translation vector followed by a rotation axis and the corresponding angle (in degrees).

See Also:
Constant Field Values

MATRIX_3X4_STRING

public static final int MATRIX_3X4_STRING
Specifies a string representation of this transformation as a 3 x 4 matrix (i.e., with the 4th row ommitted).

See Also:
Constant Field Values

MATRIX_4X4_STRING

public static final int MATRIX_4X4_STRING
Specifies a string representation of this transformation as a 4 x 4 matrix.

See Also:
Constant Field Values

R

public final RotationMatrix3d R
Rotation matrix associated with this transformation.


p

public final Vector3d p
Translation vector associated with this transformation.

Constructor Detail

RigidTransform3d

public RigidTransform3d()
Creates a new transformation initialized to the identity.


RigidTransform3d

public RigidTransform3d(Vector3d p,
                        RotationMatrix3d R)
Creates a new transformation with the specified translation vector and rotation matrix.

Parameters:
p - translation vector
R - rotation matrix

RigidTransform3d

public RigidTransform3d(RigidTransform3d X)
Creates a new transformation which is a copy of an existing one.

Parameters:
X - transform to copy

RigidTransform3d

public RigidTransform3d(Vector3d p,
                        AxisAngle axisAng)
Creates a new transformation with the specified translation vector and rotation.

Parameters:
p - translation vector
axisAng - axis-angle describing the rotation
Method Detail

mul

public void mul(RigidTransform3d X)
Post-multiplies this transformation by another and places the result in this transformation.

Parameters:
X - transformation to multiply by

mul

public void mul(RigidTransform3d X1,
                RigidTransform3d X2)
Multiplies transformation X1 by X2 and places the result in this transformation.

Parameters:
X1 - first transformation
X2 - second transformation

mulInverse

public void mulInverse(RigidTransform3d X)
Post-multiplies this transformation by the inverse of transformation X and places the result in this transformation.

Parameters:
X - right-hand transformation

mulInverseRight

public void mulInverseRight(RigidTransform3d X1,
                            RigidTransform3d X2)
Multiplies transformation X1 by the inverse of transformation X2 and places the result in this transformation.

Parameters:
X1 - left-hand transformation
X2 - right-hand transformation

mulInverseLeft

public void mulInverseLeft(RigidTransform3d X1,
                           RigidTransform3d X2)
Multiplies the inverse of transformation X1 by transformation X2 and places the result in this transformation.

Parameters:
X1 - left-hand transformation
X2 - right-hand transformation

mulInverseBoth

public void mulInverseBoth(RigidTransform3d X1,
                           RigidTransform3d X2)
Multiplies the inverse of transformation X1 by the inverse of transformation X2 and places the result in this transformation.

Parameters:
X1 - left-hand transformation
X2 - right-hand transformation

mulXyz

public void mulXyz(double x,
                   double y,
                   double z)
Post-multiplies this transformation by an implicit second transformation consisting of a pure translation, and places the result in this transformation. If p2 is the translation vector of the second transformation, then this is the equivalent of adding R p2 to this transformations translation vector.

Parameters:
x - translation component of the second transformation
y - translation component of the second transformation
z - translation component of the second transformation

mulRotX

public void mulRotX(double ang)
Post-multiplies this transformation by an implicit second transformation consisting of a pure rotation about the x axis, and places the result in this transformation. If R2 is the rotation matrix of the second transformation, then this is the equivalent of multiplying R by R2.

Parameters:
ang - rotation about the x axis (in radians) for the second transform

mulRotY

public void mulRotY(double ang)
Post-multiplies this transformation by an implicit second transformation consisting of a pure rotation about the y axis, and places the result in this transformation. If R2 is the rotation matrix of the second transformation, then this is the equivalent of multiplying R by R2.

Parameters:
ang - rotation about the y axis (in radians) for the second transform

mulRotZ

public void mulRotZ(double ang)
Post-multiplies this transformation by an implicit second transformation consisting of a pure rotation about the z axis, and places the result in this transformation. If R2 is the rotation matrix of the second transformation, then this is the equivalent of multiplying R by R2.

Parameters:
ang - rotation about the z axis (in radians) for the second transform

mulAxisAngle

public void mulAxisAngle(double ux,
                         double uy,
                         double uz,
                         double ang)
Post-multiplies this transformation by an implicit second transformation consisting of a pure rotation, expressed as an axis-angle, and places the result in this transformation. If R2 is the rotation matrix of the second transformation, then this is the equivalent of multiplying R by R2.

Parameters:
ux - rotation axis x component
uy - rotation axis y component
uz - rotation axis z component
ang - rotation angle (in radians)

mulAxisAngle

public void mulAxisAngle(AxisAngle axisAng)
Post-multiplies this transformation by an implicit second transformation consisting of a pure rotation, expressed as an axis-angle, and places the result in this transformation. If R2 is the rotation matrix of the second transformation, then this is the equivalent of multiplying R by R2.

Parameters:
axisAng - axis-angle representation of the rotation

mulRotation

public void mulRotation(RotationMatrix3d R2)
Post-multiplies this transformation by an implicit second transformation consisting of a pure rotation, and places the result in this transformation. If R2 is the rotation matrix of the second transformation, then this is the equivalent of multiplying R by R2.

Parameters:
R2 - rotation for the second transformation

mulRpy

public void mulRpy(double roll,
                   double pitch,
                   double yaw)
Post-multiplies this transformation by an implicit second transformation consisting of a pure rotation, expressed by roll-pitch-yaw angles, and places the result in this transformation. If R2 is the rotation matrix of the second transformation, then this is the equivalent of multiplying R by R2. See RotationMatrix3d.setRpy for a description of roll-pitch-yaw angles.

Parameters:
roll - first angle (radians)
pitch - second angle (radians)
yaw - third angle (radians)

mulEuler

public void mulEuler(double phi,
                     double theta,
                     double psi)
Post-multiplies this transformation by an implicit second transformation consisting of a pure rotation, expressed by Euler angles, and places the result in this transformation. If R2 is the rotation matrix of the second transformation, then this is the equivalent of multiplying R by R2. See RotationMatrix3d.setEuler for a complete description of Euler angles.

Parameters:
phi - first Euler angle (radians)
theta - second Euler angle (radians)
psi - third Euler angle (radians)

mulInverse

public boolean mulInverse(Vector4d vr,
                          Vector4d v1)
Multiplies the column vector v1 by the inverse of this transform and places the result in vr.

Overrides:
mulInverse in class AffineTransform3dObject
Parameters:
vr - result vector
v1 - vector to multiply
Returns:
false if this transform is singular

invert

public boolean invert()
Inverts this transform in place.

Overrides:
invert in class AffineTransform3dObject
Returns:
true (transform is never singular)

invert

public boolean invert(RigidTransform3d X)
Inverts transform X and places the result in this transform.

Parameters:
X - transform to invert
Returns:
true (transform is never singular)

toString

public java.lang.String toString()
Returns a string representation of this transformation as a 4 x 4 matrix.

Overrides:
toString in class MatrixObject
Returns:
String representation of this matrix

toString

public java.lang.String toString(java.lang.String numberFmtStr)
Returns a string representation of this transformation as a 4 x 4 matrix, with each number formatted according to a supplied numeric format.

Overrides:
toString in class MatrixObject
Parameters:
numberFmtStr - numeric format string (see NumberFormat)
Returns:
String representation of this matrix

toString

public java.lang.String toString(java.lang.String numberFmtStr,
                                 int outputCode)
Returns a specified string representation of this transformation, with each number formatted according to the a supplied numeric format.

Parameters:
numberFmtStr - numeric format string (see NumberFormat)
outputCode - desired representation, which should be either AXIS_ANGLE_STRING, MATRIX_4X4_STRING, or MATRIX_3X4_STRING

toString

public java.lang.String toString(NumberFormat numberFmt,
                                 int outputCode)
Returns a specified string representation of this transformation, with each number formatted according to the a supplied numeric format.

Parameters:
numberFmt - numeric format
outputCode - desired representation, which should be either AXIS_ANGLE_STRING, MATRIX_4X4_STRING, or MATRIX_3X4_STRING

scan

public void scan(java.io.StreamTokenizer stok)
          throws java.io.IOException
Reads the contents of this transformation from a StreamTokenizer. There are four allowed formats, each of which is delimited by square brackets.

The first format is a set of 7 numbers in which the first three numbers give the x, y, and z ccordinates of the translation vector, the next three numbers give the x, y, and z coordinates of a rotation axis, and the last number gives a rotation angle, in degrees, about that axis. For example,

 [ 10 20 30  0 1 0 90 ]
 
defines a transformation with a translation of (10, 20, 30{) and a rotation of 90 degrees about the y axis.

The second format format is a set of 12 numbers describing the first three rows of the transformation matrix in row-major order. For example,

 [ 0  -1  0  10 
   1   0  0  20
   0   0  1  20 ]
 
defines a transformation with a translation of (10,20, 30) and a rotation of 90 degrees about the z axis.

The third format is a set of 16 numbers describing all elements of the transformation matrix in row-major order. The last four numbers, which represent the fourth row, are actually ignored and instead assumed to be 0, 0, 0, 1, in keeping with the structure of the transformation matrix. A transformation with a translation of (30, 40, 50) and a rotation of 180 degrees about the x axis would be represented as

 [  1  0  0  30
    0 -1  0  40
    0  0 -1  50 
    0  0  0  1 ]
 

The fourth format consists of a series of simple translational or rotational transformation, which are the multiplied together to form the final transformation. The following simple transformations may be specified:

trans x y z
A translation with the indicated x, y, and z values;
rotX ang
A rotation of "ang" degrees about the x axis;
rotY ang
A rotation of "ang" degrees about the y axis;
rotZ ang
A rotation of "ang" degrees about the z axis;
rotAxis x y z ang
A rotation of "ang" degrees about an arbitrary axis parallel to x, y, and z.
For example, the string
 [ rotX 45 trans 0 0 100 rot 1 1 0 90 ]
 
describes a transformation which the product of a rotation of 45 degrees about the y axis, a translation of 100 units along the z axis, and a rotation of 90 degrees about the axis (1, 1, 0).

Note:This method disables numeric parsing in the StreamTokenizer. This is because the method does its own numeric parsing, in order to handle exponents.

Overrides:
scan in class MatrixObject
Parameters:
stok - StreamTokenizer from which to read the transformation
Throws:
java.io.IOException - if an I/O error occured or if the transformation description is not consistent with one of the above formats.

main

public static void main(java.lang.String[] args)