maspack.matrix
Class AffineTransform3dBase

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

public abstract class AffineTransform3dBase
extends DenseMatrixBase
implements java.io.Serializable, Clonable

Base class for 4 x 4 matrices representing 3D affine transformations. A 3D affine transformation applied to a 3-vector v has the form
A v + b
In homogeneous coordinates, this is represented by a 4 x 4 matrix of the form

     [  A   p  ]
 M = [         ]
     [  0   1  ]
 

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface maspack.matrix.Matrix
Matrix.Partition, Matrix.WriteFormat
 
Field Summary
 
Fields inherited from interface maspack.matrix.Matrix
INDEFINITE, POSITIVE_DEFINITE, SPD, SYMMETRIC
 
Constructor Summary
AffineTransform3dBase()
           
 
Method Summary
 AffineTransform3dBase clone()
           
 int colSize()
          Returns the number of columns in this matrix (which is always 4).
 boolean epsilonEquals(AffineTransform3dBase X, double epsilon)
          Returns true if the elements of this transformation equal those of transform X1within a prescribed tolerance epsilon.
 boolean equals(AffineTransform3dBase X)
          Returns true if the elements of this transformation exactly equal those of transform X1.
 void get(double[] values)
          Copies the elements of this matrix into an array of doubles.
 double get(int i, int j)
          Gets a single element of this matrix.
 void getColumn(int j, double[] values)
          Copies a column of this matrix into an array of doubles.
 void getColumn(int j, double[] values, int off)
          Copies a column of this matrix into an array of doubles, starting at a specified offset.
 Matrix3dBase getMatrix()
          Returns the matrix assiciated with this affine transform.
 void getMatrixComponents(RotationMatrix3d R, Vector3d s, Matrix3d X)
          Returns the shear, scaling, and rotational components of this AffineTransform.
 Vector3d getOffset()
          Returns the offset vector assiciated with this affine transform.
 void getRow(int i, double[] values)
          Copies a row of this matrix into an array of doubles.
 void getRow(int i, double[] values, int off)
          Copies a row of this matrix into an array of doubles, starting at a specified offset.
 boolean invert()
          Inverts this transform in place.
 boolean isIdentity()
          Returns true if this transform equals the identity.
 void leftRigidFactor(AffineTransform3d XS, RigidTransform3d XR)
          Factors this affine transform into the product of a stretch-shear transform (with no translation) and a rigid transform:
 void mul(Vector4d vr)
          Multiplies the column vector vr by this transform and places the result back in vr.
 void mul(Vector4d vr, Vector4d v1)
          Multiplies the column vector v1 by this transform and places the result in vr.
 boolean mulInverse(Vector4d vr)
          Multiplies the column vector vr by the inverse of this transform and places the result back in vr.
 boolean mulInverse(Vector4d vr, Vector4d v1)
          Multiplies the column vector v1 by the inverse of this transform and places the result in vr.
 int rowSize()
          Returns the number of rows in this matrix (which is always 4).
 void set(AffineTransform3dBase A)
           
 void set(double[] vals)
          Sets the elements of this matrix from an array of doubles.
 void set(int i, int j, double value)
          Sets a single element of this matrix.
 void setColumn(int j, double[] values)
          Sets a column of this matrix from an array of doubles.
 void setIdentity()
          Sets the transformation to the identity.
 void setRotation(AxisAngle axisAng)
          Sets the matrix component of this affine transform to an explicit rotation.
 void setRotation(Quaternion quat)
          Sets the matrix component of this affine transform to an explicit rotation.
 void setRotation(RotationMatrix3d R)
          Sets the matrix component of this affine transform to an explicit rotation.
 void setRow(int i, double[] values)
          Set a row of this matrix from an array of doubles.
 void setTranslation(Vector3d p)
          Sets the translation component of this affine transform.
 
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, toString, 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
 

Constructor Detail

AffineTransform3dBase

public AffineTransform3dBase()
Method Detail

getMatrix

public Matrix3dBase getMatrix()
Returns the matrix assiciated with this affine transform.

Returns:
matrix

getOffset

public Vector3d getOffset()
Returns the offset vector assiciated with this affine transform.

Returns:
offset vector

colSize

public int colSize()
Returns the number of columns in this matrix (which is always 4).

Specified by:
colSize in interface LinearTransformNd
Specified by:
colSize in interface Matrix
Specified by:
colSize in class MatrixBase
Returns:
4

rowSize

public int rowSize()
Returns the number of rows in this matrix (which is always 4).

Specified by:
rowSize in interface LinearTransformNd
Specified by:
rowSize in interface Matrix
Specified by:
rowSize in class MatrixBase
Returns:
4

get

public double get(int i,
                  int j)
Gets a single element of this matrix.

Specified by:
get in interface Matrix
Specified by:
get in class MatrixBase
Parameters:
i - element row index
j - element column index
Returns:
element value

get

public void get(double[] values)
Copies the elements of this matrix into an array of doubles. The elements are stored using row-major order, so that element (i,j) is stored at location i*colSize()+j.

Specified by:
get in interface Matrix
Overrides:
get in class MatrixBase
Parameters:
values - array into which values are copied

getColumn

public void getColumn(int j,
                      double[] values)
Copies a column of this matrix into an array of doubles.

Specified by:
getColumn in interface Matrix
Overrides:
getColumn in class MatrixBase
Parameters:
j - column index
values - array into which the column is copied

getColumn

public void getColumn(int j,
                      double[] values,
                      int off)
Copies a column of this matrix into an array of doubles, starting at a specified offset.

Specified by:
getColumn in interface Matrix
Overrides:
getColumn in class MatrixBase
Parameters:
j - column index
values - array into which the column is copied
off - offset in values where copying should begin

getRow

public void getRow(int i,
                   double[] values)
Copies a row of this matrix into an array of doubles.

Specified by:
getRow in interface Matrix
Overrides:
getRow in class MatrixBase
Parameters:
i - row index
values - array into which the row is copied

getRow

public void getRow(int i,
                   double[] values,
                   int off)
Copies a row of this matrix into an array of doubles, starting at a specified offset.

Specified by:
getRow in interface Matrix
Overrides:
getRow in class MatrixBase
Parameters:
i - row index
values - array into which the row is copied
off - offset in values where copying should begin

set

public final void set(AffineTransform3dBase A)

set

public void set(int i,
                int j,
                double value)
Sets a single element of this matrix.

Specified by:
set in interface DenseMatrix
Specified by:
set in class DenseMatrixBase
Parameters:
i - element row index
j - element column index
value - element value

set

public void set(double[] vals)
Sets the elements of this matrix from an array of doubles. The elements in the array should be stored using row-major order, so that element (i,j) is stored at location i*colSize()+j.

Specified by:
set in interface DenseMatrix
Overrides:
set in class DenseMatrixBase
Parameters:
vals - array from which values are copied

setColumn

public void setColumn(int j,
                      double[] values)
Sets a column of this matrix from an array of doubles.

Specified by:
setColumn in interface DenseMatrix
Overrides:
setColumn in class DenseMatrixBase
Parameters:
j - column index
values - array from which column values are copied

setRow

public void setRow(int i,
                   double[] values)
Set a row of this matrix from an array of doubles.

Specified by:
setRow in interface DenseMatrix
Overrides:
setRow in class DenseMatrixBase
Parameters:
i - row index
values - array from which the row is copied

setTranslation

public void setTranslation(Vector3d p)
Sets the translation component of this affine transform.

Parameters:
p - translation vector

setRotation

public void setRotation(AxisAngle axisAng)
Sets the matrix component of this affine transform to an explicit rotation.

Parameters:
axisAng - axis-angle describing the rotation

setRotation

public void setRotation(Quaternion quat)
Sets the matrix component of this affine transform to an explicit rotation.

Parameters:
quat - quaternion describing the rotation

setRotation

public void setRotation(RotationMatrix3d R)
Sets the matrix component of this affine transform to an explicit rotation.

Parameters:
R - rotation matrix

setIdentity

public void setIdentity()
Sets the transformation to the identity.


mul

public void mul(Vector4d vr,
                Vector4d v1)
Multiplies the column vector v1 by this transform and places the result in vr.

Parameters:
vr - result vector
v1 - vector to multiply

mul

public void mul(Vector4d vr)
Multiplies the column vector vr by this transform and places the result back in vr.

Parameters:
vr - vector to multiply (in place)

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.

Parameters:
vr - result vector
v1 - vector to multiply
Returns:
false if this transform is singular

mulInverse

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

Parameters:
vr - vector to multiply (in place)
Returns:
false if this transform is singular

invert

public boolean invert()
Inverts this transform in place.

Returns:
false if this transform is singular

epsilonEquals

public boolean epsilonEquals(AffineTransform3dBase X,
                             double epsilon)
Returns true if the elements of this transformation equal those of transform X1within a prescribed tolerance epsilon.

Parameters:
X - transform to compare with
epsilon - comparison tolerance
Returns:
false if the transforms are not equal within the specified tolerance

equals

public boolean equals(AffineTransform3dBase X)
Returns true if the elements of this transformation exactly equal those of transform X1.

Parameters:
X - transform to compare with
Returns:
false if the transforms are not equal

getMatrixComponents

public void getMatrixComponents(RotationMatrix3d R,
                                Vector3d s,
                                Matrix3d X)
Returns the shear, scaling, and rotational components of this AffineTransform. This is done by computing the SVD of the transform:
     M = U S V'
 
The rotation is then set to U, the scale factors are set to the diagonal elements of S, and the shear is set to U'.

Parameters:
R - returns the rotation matrix
s - returns the three scaling factors
X - returns the shearing transform

leftRigidFactor

public void leftRigidFactor(AffineTransform3d XS,
                            RigidTransform3d XR)
Factors this affine transform into the product of a stretch-shear transform (with no translation) and a rigid transform:
    this = XS XR
 

Parameters:
XS - returns the stretch-shear transform (optional argument)
XR - returns the rigid transform (optional argument)

isIdentity

public boolean isIdentity()
Returns true if this transform equals the identity.

Returns:
true if this transform equals the identity

clone

public AffineTransform3dBase clone()
Specified by:
clone in interface Clonable
Overrides:
clone in class java.lang.Object