maspack.matrix
Class AffineTransform3d

java.lang.Object
  extended by maspack.matrix.MatrixBase
      extended by maspack.matrix.DenseMatrixBase
          extended by maspack.matrix.AffineTransform3dBase
              extended by maspack.matrix.AffineTransform3d
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, DenseMatrix, LinearTransformNd, Matrix, Clonable

public class AffineTransform3d
extends AffineTransform3dBase
implements Clonable

A 4 x 4 matrix which implements general 3D affine transformations. The matrix has the specific form

     [  A   p  ]
 M = [         ]
     [  0   1  ]
 
where A is a 3 x 3 matrix and p is a 3-vector. In homogeneous coordinates, this implements an affine transform of the form
A v + b

In this class, the fields A and p are exposed, and users can manipulate them as desired. This allows us to minimize the number of methds in the AffineTransform3d class itself.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface maspack.matrix.Matrix
Matrix.Partition, Matrix.WriteFormat
 
Field Summary
 Matrix3d A
          Matrix component.
static AffineTransform3d IDENTITY
          Global identity transform.
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
          Vector component.
 
Fields inherited from interface maspack.matrix.Matrix
INDEFINITE, POSITIVE_DEFINITE, SPD, SYMMETRIC
 
Constructor Summary
AffineTransform3d()
          Creates an AffineTransform3d and initializes it to the identity.
AffineTransform3d(AffineTransform3dBase X)
           
AffineTransform3d(double m00, double m01, double m02, double px, double m10, double m11, double m12, double py, double m20, double m21, double m22, double pz)
           
AffineTransform3d(Matrix3d A, Vector3d p)
          Creates an AffineTransform3d and initializes its components to the specified values.
 
Method Summary
 void applyScaling(double sx, double sy, double sz)
          Scales the columns of A by the specified amounts.
 AffineTransform3d clone()
           
static AffineTransform3d createScaling(double s)
          Creates an AffineTransform3d which performs uniform scaling along all axes.
static AffineTransform3d createScaling(double sx, double sy, double sz)
          Creates an AffineTransform3d which performs scaling along the x, y, and z axes.
 void factorA(RotationMatrix3d R, Vector3d scale, Vector3d shear)
          Factors the A matrix of this transformation into rotation, scale, and shear components, so that
 void fit(java.util.ArrayList<Point3d> p, java.util.ArrayList<Point3d> q)
          Sets this affine transform to one that provides the best fit of q to p in the least-squares sense: p ~ X q
 Vector3d fitOrthogonal(java.util.ArrayList<Point3d> p, java.util.ArrayList<Point3d> q)
          Sets this affine transform to one that provides the best fit of q to p in the least-squares sense: p ~ X q, where X has orthogonal columns, corresponding to a rigid transform with three scale factors (one for each dimension)
 Vector3d fitOrthogonal(java.util.ArrayList<Point3d> p, java.util.ArrayList<Point3d> q, double threshold)
          Sets this affine transform to one that provides the best fit of q to p in the least-squares sense: p ~ X q, where X has orthogonal columns, corresponding to a rigid transform with three scale factors (one for each dimension).
 void fitRigid(java.util.ArrayList<Point3d> p, java.util.ArrayList<Point3d> q, boolean scale)
          Sets this affine transform to one that provides the best fit of q to p in the least-squares sense: p ~ X q, where X is a rigid transformation with a single scale factor
 boolean invert()
          Inverts this transform in place.
 boolean invert(AffineTransform3dBase X)
          Inverts transform X and places the result in this transform.
 void mul(AffineTransform3dBase X)
          Multiplies this transformation transformation X and places the result in this transformation.
 void mul(AffineTransform3dBase X1, AffineTransform3dBase X2)
          Multiplies transformation X1 by transformation X2 and places the result in this transformation.
 boolean mulInverse(AffineTransform3dBase X)
          Multiplies this transformation by the inverse of transformation X and places the result in this transformation.
 boolean mulInverseBoth(AffineTransform3dBase X1, AffineTransform3dBase X2)
          Multiplies the inverse of transformation X1 by the inverse of transformation X2 and places the result in this transformation.
 boolean mulInverseLeft(AffineTransform3dBase X1, AffineTransform3dBase X2)
          Multiplies the inverse of transformation X1 by transformation X2 and places the result in this transformation.
 boolean mulInverseRight(AffineTransform3dBase X1, AffineTransform3dBase X2)
          Multiplies transformation X1 by the inverse of transformation X2 and places the result in this transformation.
 void set(RigidTransform3d X)
          Sets this affine transform to the rigid body transform described by X.
 void setA(RotationMatrix3d R, Vector3d scale, Vector3d shear)
          Sets the A matrix of this transformation from rotation, scale, and shear components, so that
 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.AffineTransform3dBase
colSize, epsilonEquals, equals, get, get, getColumn, getColumn, getMatrix, getMatrixComponents, getOffset, getRow, getRow, isIdentity, leftRigidFactor, mul, mul, mulInverse, mulInverse, rowSize, set, set, set, setColumn, setIdentity, setRotation, setRotation, setRotation, setRow, setTranslation
 
Methods inherited from class maspack.matrix.DenseMatrixBase
add, checkConsistency, set, set, set, set, setCCSValues, setColumn, setCRSValues, setRow, setSubMatrix
 
Methods inherited from class maspack.matrix.MatrixBase
containsNaN, determinant, epsilonEquals, equals, frobeniusNorm, get, getCCSIndices, getCCSIndices, getCCSValues, getCCSValues, getColumn, getCRSIndices, getCRSIndices, getCRSValues, getCRSValues, getDefaultFormat, getRow, getSize, getSubMatrix, hasNaN, idString, infinityNorm, isFixedSize, isSymmetric, mul, mul, mul, mulAdd, mulAdd, mulAdd, mulTranspose, mulTranspose, mulTranspose, mulTransposeAdd, mulTransposeAdd, mulTransposeAdd, numNonZeroVals, numNonZeroVals, oneNorm, scan, setCRSValues, setDefaultFormat, setSize, toString, trace, write, write, write, write, write, writeToFile
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface maspack.matrix.Matrix
determinant, epsilonEquals, equals, frobeniusNorm, getCCSIndices, getCCSIndices, getCCSValues, getCCSValues, getColumn, getCRSIndices, getCRSIndices, getCRSValues, getCRSValues, getRow, getSize, getSubMatrix, infinityNorm, isFixedSize, isSymmetric, mul, mul, mul, mulAdd, mulAdd, mulAdd, mulTranspose, mulTranspose, mulTranspose, mulTransposeAdd, mulTransposeAdd, mulTransposeAdd, numNonZeroVals, numNonZeroVals, oneNorm, scan, setSize, toString, trace, write, write, write
 

Field Detail

IDENTITY

public static final AffineTransform3d IDENTITY
Global identity transform. Should not be modified.


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

A

public final Matrix3d A
Matrix component.


p

public final Vector3d p
Vector component.

Constructor Detail

AffineTransform3d

public AffineTransform3d()
Creates an AffineTransform3d and initializes it to the identity.


AffineTransform3d

public AffineTransform3d(Matrix3d A,
                         Vector3d p)
Creates an AffineTransform3d and initializes its components to the specified values.

Parameters:
A - value for the A matrix
p - value for the p vector

AffineTransform3d

public AffineTransform3d(AffineTransform3dBase X)

AffineTransform3d

public AffineTransform3d(double m00,
                         double m01,
                         double m02,
                         double px,
                         double m10,
                         double m11,
                         double m12,
                         double py,
                         double m20,
                         double m21,
                         double m22,
                         double pz)
Method Detail

mul

public void mul(AffineTransform3dBase X)
Multiplies this transformation transformation X and places the result in this transformation.

Parameters:
X - right-hand transformation

mul

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

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

mulInverse

public boolean mulInverse(AffineTransform3dBase X)
Multiplies this transformation by the inverse of transformation X and places the result in this transformation.

Parameters:
X - right-hand transformation
Returns:
false if X is singular

mulInverseRight

public boolean mulInverseRight(AffineTransform3dBase X1,
                               AffineTransform3dBase 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
Returns:
false if X2 is singular

mulInverseLeft

public boolean mulInverseLeft(AffineTransform3dBase X1,
                              AffineTransform3dBase 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
Returns:
false if X1 is singular

mulInverseBoth

public boolean mulInverseBoth(AffineTransform3dBase X1,
                              AffineTransform3dBase 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
Returns:
false if either X1 or X2 is singular

invert

public boolean invert()
Inverts this transform in place.

Overrides:
invert in class AffineTransform3dBase
Returns:
false if this transform is singular

invert

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

Parameters:
X - transform to invert
Returns:
false if transform X is singular

set

public void set(RigidTransform3d X)
Sets this affine transform to the rigid body transform described by X.

Parameters:
X - rigid body transform to copy

applyScaling

public void applyScaling(double sx,
                         double sy,
                         double sz)
Scales the columns of A by the specified amounts. This is equivalent to post-multiplying A by a diagonal matrix. Note that the resulting scaling effect with be in addition to any previous scaling effect.

Parameters:
sx - x scale factor
sy - y scale factor
sz - z scale factor

factorA

public void factorA(RotationMatrix3d R,
                    Vector3d scale,
                    Vector3d shear)
Factors the A matrix of this transformation into rotation, scale, and shear components, so that
 A = R S X
 
where R is a right-handed rotation matrix, S is a diagonal scaling matrix, and X is a shear matrix of the form
     [ 1   xy  xz ]
 X = [ 0   1   yz ]
     [ 0   0   1  ]
 

Parameters:
R - if non-null, returns the rotation matrix
scale - if non-null, returns the diagonal components of S
shear - if non-null, returns the components xy, xz, yz of X

setA

public void setA(RotationMatrix3d R,
                 Vector3d scale,
                 Vector3d shear)
Sets the A matrix of this transformation from rotation, scale, and shear components, so that
 A = R S X
 
where R is a right-handed rotation matrix, S is a diagonal scaling matrix, and X is a shear matrix of the form
     [ 1  xy  xz ]
 X = [ 0   1  yz ]
     [ 0   0  1  ]
 

Parameters:
R - the rotation matrix
scale - diagonal components of S
shear - components xy, xz, yz of X

createScaling

public static AffineTransform3d createScaling(double sx,
                                              double sy,
                                              double sz)
Creates an AffineTransform3d which performs scaling along the x, y, and z axes.

Parameters:
sx - x scale factor
sy - y scale factor
sz - z scale factor

createScaling

public static AffineTransform3d createScaling(double s)
Creates an AffineTransform3d which performs uniform scaling along all axes.

Parameters:
s - scale factor

clone

public AffineTransform3d clone()
Specified by:
clone in interface Clonable
Overrides:
clone in class AffineTransform3dBase

fit

public void fit(java.util.ArrayList<Point3d> p,
                java.util.ArrayList<Point3d> q)
         throws ImproperSizeException
Sets this affine transform to one that provides the best fit of q to p in the least-squares sense: p ~ X q

Parameters:
p - set of target 3d points
q - set of input 3d points
Throws:
ImproperSizeException

fitRigid

public void fitRigid(java.util.ArrayList<Point3d> p,
                     java.util.ArrayList<Point3d> q,
                     boolean scale)
              throws ImproperSizeException
Sets this affine transform to one that provides the best fit of q to p in the least-squares sense: p ~ X q, where X is a rigid transformation with a single scale factor

Parameters:
p - set of target 3d points
q - set of input 3d points
scale - allow scaling
Throws:
ImproperSizeException

fitOrthogonal

public Vector3d fitOrthogonal(java.util.ArrayList<Point3d> p,
                              java.util.ArrayList<Point3d> q,
                              double threshold)
Sets this affine transform to one that provides the best fit of q to p in the least-squares sense: p ~ X q, where X has orthogonal columns, corresponding to a rigid transform with three scale factors (one for each dimension). Uses an iterative procedure, stops when the scale factors change less than a given threshold

Parameters:
p - set of target 3d points
q - set of input 3d points
threshold - algorithm stops when ||s_{i} - s_{i-1}||/||s_{i-1}|| < threshold
Returns:
3-vector containing the scale factors

fitOrthogonal

public Vector3d fitOrthogonal(java.util.ArrayList<Point3d> p,
                              java.util.ArrayList<Point3d> q)
                       throws ImproperSizeException
Sets this affine transform to one that provides the best fit of q to p in the least-squares sense: p ~ X q, where X has orthogonal columns, corresponding to a rigid transform with three scale factors (one for each dimension)

Parameters:
p - set of target 3d points
q - set of input 3d points
Returns:
a 3-vector containing the scale factors
Throws:
ImproperSizeException

toString

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

Overrides:
toString in class MatrixBase
Returns:
String representation of this matrix
See Also:
MatrixBase.toString(String)

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 MatrixBase
Parameters:
numberFmtStr - numeric format string (see NumberFormat)
Returns:
String representation of this vector

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 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 MATRIX_4X4_STRING, or MATRIX_3X4_STRING