maspack.matrix
Class AffineTransform2d

java.lang.Object
  extended by maspack.matrix.MatrixBase
      extended by maspack.matrix.DenseMatrixBase
          extended by maspack.matrix.AffineTransform2dBase
              extended by maspack.matrix.AffineTransform2d
All Implemented Interfaces:
DenseMatrix, LinearTransformNd, Matrix

public class AffineTransform2d
extends AffineTransform2dBase

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

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


Nested Class Summary
 
Nested classes/interfaces inherited from interface maspack.matrix.Matrix
Matrix.Partition, Matrix.WriteFormat
 
Field Summary
 Matrix2d A
          Matrix component.
static AffineTransform2d IDENTITY
          Global identity transform.
 Vector2d p
          Vector component.
 
Fields inherited from interface maspack.matrix.Matrix
INDEFINITE, POSITIVE_DEFINITE, SPD, SYMMETRIC
 
Constructor Summary
AffineTransform2d()
          Creates an AffineTransform2d and initializes it to the identity.
AffineTransform2d(Vector2d p, Matrix2d A)
          Creates an AffineTransform2d and initializes its components to the specified values.
 
Method Summary
 void fit(java.util.ArrayList<Point2d> p, java.util.ArrayList<Point2d> q)
          Sets this affine transform to one that provides the best fit of q to p in the least-squares sense: p ~ X q
 boolean invert()
          Inverts this transform in place.
 boolean invert(AffineTransform2dBase X)
          Inverts transform X and places the result in this transform.
 void mul(AffineTransform2dBase X)
          Multiplies this transformation transformation X and places the result in this transformation.
 void mul(AffineTransform2dBase X1, AffineTransform2dBase X2)
          Multiplies transformation X1 by transformation X2 and places the result in this transformation.
 boolean mulInverse(AffineTransform2dBase X)
          Multiplies this transformation by the inverse of transformation X and places the result in this transformation.
 boolean mulInverseBoth(AffineTransform2dBase X1, AffineTransform2dBase X2)
          Multiplies the inverse of transformation X1 by the inverse of transformation X2 and places the result in this transformation.
 boolean mulInverseLeft(AffineTransform2dBase X1, AffineTransform2dBase X2)
          Multiplies the inverse of transformation X1 by transformation X2 and places the result in this transformation.
 boolean mulInverseRight(AffineTransform2dBase X1, AffineTransform2dBase X2)
          Multiplies transformation X1 by the inverse of transformation X2 and places the result in this transformation.
 void set(RigidTransform2d X)
          Sets this affine transform to the rigid body transform described by X.
 void setRandom()
          Sets the elements of this matrix to uniformly distributed random values in the range -0.5 (inclusive) to 0.5 (exclusive).
 
Methods inherited from class maspack.matrix.AffineTransform2dBase
colSize, epsilonEquals, equals, get, get, getColumn, getColumn, getRow, getRow, mul, mul, mulInverse, mulInverse, rowSize, set, set, setColumn, setIdentity, setRow
 
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
 

Field Detail

IDENTITY

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


A

public final Matrix2d A
Matrix component.


p

public final Vector2d p
Vector component.

Constructor Detail

AffineTransform2d

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


AffineTransform2d

public AffineTransform2d(Vector2d p,
                         Matrix2d A)
Creates an AffineTransform2d and initializes its components to the specified values.

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

mul

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

Parameters:
X - right-hand transformation

mul

public void mul(AffineTransform2dBase X1,
                AffineTransform2dBase 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(AffineTransform2dBase 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(AffineTransform2dBase X1,
                               AffineTransform2dBase 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(AffineTransform2dBase X1,
                              AffineTransform2dBase 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(AffineTransform2dBase X1,
                              AffineTransform2dBase 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 AffineTransform2dBase
Returns:
false if this transform is singular

invert

public boolean invert(AffineTransform2dBase 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(RigidTransform2d X)
Sets this affine transform to the rigid body transform described by X.

Overrides:
set in class AffineTransform2dBase
Parameters:
X - rigid body transform to copy

fit

public void fit(java.util.ArrayList<Point2d> p,
                java.util.ArrayList<Point2d> 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 2d points
q - set of input 2d points
Throws:
ImproperSizeException

setRandom

public void setRandom()
Description copied from class: MatrixBase
Sets the elements of this matrix to uniformly distributed random values in the range -0.5 (inclusive) to 0.5 (exclusive).