de.lmu.ifi.dbs.elki.math.linearalgebra
Class AffineTransformation

java.lang.Object
  extended by de.lmu.ifi.dbs.elki.math.linearalgebra.AffineTransformation

public class AffineTransformation
extends Object

Affine transformations implemented using homogeneous coordinates. The use of homogeneous coordinates allows the combination of multiple affine transformations (rotations, translations, scaling) into a single matrix operation (of dimensionality dim+1), and also the construction of an inverse transformation.


Field Summary
private  int dim
          the dimensionality of the transformation
private  Matrix inv
          the inverse transformation
private  Matrix trans
          The transformation matrix of dim+1 x dim+1 for homogeneous coordinates
 
Constructor Summary
AffineTransformation(int dim)
          Constructor for an identity transformation.
AffineTransformation(int dim, Matrix trans, Matrix inv)
          Trivial constructor with all fields, mostly for cloning
 
Method Summary
 void addAxisReflection(int axis)
          Add a reflection along the given axis.
 void addMatrix(Matrix m)
          Add a matrix operation to the matrix.
 void addRotation(int axis1, int axis2, double angle)
          Convenience function to apply a rotation in 2 dimensions.
 void addScaling(double scale)
          Simple linear (symmetric) scaling.
 void addTranslation(Vector v)
          Add a translation operation to the matrix
 Vector apply(Vector v)
          Apply the transformation onto a vector
 Vector applyInverse(Vector v)
          Apply the inverse transformation onto a vector
 Vector applyRelative(Vector v)
          Apply the transformation onto a vector
 Vector applyRelativeInverse(Vector v)
          Apply the inverse transformation onto a vector
 AffineTransformation clone()
          Return a clone of the affine transformation
 int getDimensionality()
          Query dimensionality of the transformation.
 Matrix getInverse()
          Get a copy of the inverse matrix
 Matrix getTransformation()
          Get a copy of the transformation matrix
 Vector homogeneRelativeVector(Vector v)
          Transform a relative vector into homogeneous coordinates.
 Vector homogeneVector(Vector v)
          Transform an absolute vector into homogeneous coordinates.
static AffineTransformation reorderAxesTransformation(int dim, int[] axes)
          Generate a transformation that reorders axes in the given way.
 Vector unhomogeneRelativeVector(Vector v)
          Project an homogeneous vector back into the original space.
 Vector unhomogeneVector(Vector v)
          Project an homogeneous vector back into the original space.
private  void updateInverse()
          Compute the inverse transformation matrix
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dim

private int dim
the dimensionality of the transformation


trans

private Matrix trans
The transformation matrix of dim+1 x dim+1 for homogeneous coordinates


inv

private Matrix inv
the inverse transformation

Constructor Detail

AffineTransformation

public AffineTransformation(int dim)
Constructor for an identity transformation.

Parameters:
dim - dimensionality

AffineTransformation

public AffineTransformation(int dim,
                            Matrix trans,
                            Matrix inv)
Trivial constructor with all fields, mostly for cloning

Parameters:
dim - dimensionality
trans - transformation matrix
inv - inverse matrix
Method Detail

reorderAxesTransformation

public static AffineTransformation reorderAxesTransformation(int dim,
                                                             int[] axes)
Generate a transformation that reorders axes in the given way. The list of axes to be used should not contain duplicates, or the resulting matrix will not be invertible. It does not have to be complete however, in particular an empty list will result in the identity transform: unmentioned axes will be appended in their original order.

Parameters:
dim - Dimensionality of vector space (resulting Matrix will be dim+1 x dim+1)
axes - (Partial) list of axes
Returns:
new transformation to do the requested reordering

clone

public AffineTransformation clone()
Return a clone of the affine transformation

Overrides:
clone in class Object
Returns:
cloned affine transformation

getDimensionality

public int getDimensionality()
Query dimensionality of the transformation.

Returns:
dimensionality

addTranslation

public void addTranslation(Vector v)
Add a translation operation to the matrix

Parameters:
v - translation vector

addMatrix

public void addMatrix(Matrix m)
Add a matrix operation to the matrix. Be careful to use only invertible matrices if you want an invertible affine transformation.

Parameters:
m - matrix (should be invertible)

addRotation

public void addRotation(int axis1,
                        int axis2,
                        double angle)
Convenience function to apply a rotation in 2 dimensions.

Parameters:
axis1 - first dimension
axis2 - second dimension
angle - rotation angle in radians.

addAxisReflection

public void addAxisReflection(int axis)
Add a reflection along the given axis.

Parameters:
axis - Axis number to do the reflection at.

addScaling

public void addScaling(double scale)
Simple linear (symmetric) scaling.

Parameters:
scale - Scaling factor

getTransformation

public Matrix getTransformation()
Get a copy of the transformation matrix

Returns:
copy of the transformation matrix

getInverse

public Matrix getInverse()
Get a copy of the inverse matrix

Returns:
a copy of the inverse transformation matrix

updateInverse

private void updateInverse()
Compute the inverse transformation matrix


homogeneVector

public Vector homogeneVector(Vector v)
Transform an absolute vector into homogeneous coordinates.

Parameters:
v - initial vector
Returns:
vector of dim+1, with new column having the value 1.0

homogeneRelativeVector

public Vector homogeneRelativeVector(Vector v)
Transform a relative vector into homogeneous coordinates.

Parameters:
v - initial vector
Returns:
vector of dim+1, with new column having the value 0.0

unhomogeneVector

public Vector unhomogeneVector(Vector v)
Project an homogeneous vector back into the original space.

Parameters:
v - Matrix of 1 x dim+1 containing the homogeneous vector
Returns:
vector of dimension dim

unhomogeneRelativeVector

public Vector unhomogeneRelativeVector(Vector v)
Project an homogeneous vector back into the original space.

Parameters:
v - Matrix of 1 x dim+1 containing the homogeneous vector
Returns:
vector of dimension dim

apply

public Vector apply(Vector v)
Apply the transformation onto a vector

Parameters:
v - vector of dimensionality dim
Returns:
transformed vector of dimensionality dim

applyInverse

public Vector applyInverse(Vector v)
Apply the inverse transformation onto a vector

Parameters:
v - vector of dimensionality dim
Returns:
transformed vector of dimensionality dim

applyRelative

public Vector applyRelative(Vector v)
Apply the transformation onto a vector

Parameters:
v - vector of dimensionality dim
Returns:
transformed vector of dimensionality dim

applyRelativeInverse

public Vector applyRelativeInverse(Vector v)
Apply the inverse transformation onto a vector

Parameters:
v - vector of dimensionality dim
Returns:
transformed vector of dimensionality dim

Release 0.4.0 (2011-09-20_1324)