Package elki.math.linearalgebra
Class AffineTransformation
- java.lang.Object
-
- elki.math.linearalgebra.AffineTransformation
-
public class AffineTransformation extends java.lang.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.
- Since:
- 0.2
- Author:
- Erich Schubert
-
-
Constructor Summary
Constructors Constructor Description AffineTransformation(int dim)
Constructor for an identity transformation.AffineTransformation(int dim, double[][] trans, double[][] inv)
Trivial constructor with all fields, mostly for cloning
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAxisReflection(int axis)
Add a reflection along the given axis.void
addMatrix(double[][] 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(double[] v)
Add a translation operation to the matrixdouble[]
apply(double[] v)
Apply the transformation onto a vectordouble[]
applyInverse(double[] v)
Apply the inverse transformation onto a vectordouble[]
applyRelative(double[] v)
Apply the transformation onto a vectordouble[]
applyRelativeInverse(double[] v)
Apply the inverse transformation onto a vectorint
getDimensionality()
Query dimensionality of the transformation.double[][]
getInverse()
Get a the inverse matrixdouble[][]
getTransformation()
Get the transformation matrixdouble[]
homogeneRelativeVector(double[] v)
Transform a relative vector into homogeneous coordinates.double[]
homogeneVector(double[] 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.double[]
unhomogeneRelativeVector(double[] v)
Project an homogeneous vector back into the original space.double[]
unhomogeneVector(double[] v)
Project an homogeneous vector back into the original space.private void
updateInverse()
Compute the inverse transformation matrix
-
-
-
Constructor Detail
-
AffineTransformation
public AffineTransformation(int dim)
Constructor for an identity transformation.- Parameters:
dim
- dimensionality
-
AffineTransformation
public AffineTransformation(int dim, double[][] trans, double[][] inv)
Trivial constructor with all fields, mostly for cloning- Parameters:
dim
- dimensionalitytrans
- transformation matrix (will NOT be copied!)inv
- inverse matrix (will NOT be copied!)
-
-
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
-
getDimensionality
public int getDimensionality()
Query dimensionality of the transformation.- Returns:
- dimensionality
-
addTranslation
public void addTranslation(double[] v)
Add a translation operation to the matrix- Parameters:
v
- translation vector
-
addMatrix
public void addMatrix(double[][] 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 dimensionaxis2
- second dimensionangle
- 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 double[][] getTransformation()
Get the transformation matrix- Returns:
- the transformation matrix
-
getInverse
public double[][] getInverse()
Get a the inverse matrix- Returns:
- the inverse transformation matrix
-
updateInverse
private void updateInverse()
Compute the inverse transformation matrix
-
homogeneVector
public double[] homogeneVector(double[] 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 double[] homogeneRelativeVector(double[] 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 double[] unhomogeneVector(double[] 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 double[] unhomogeneRelativeVector(double[] 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 double[] apply(double[] v)
Apply the transformation onto a vector- Parameters:
v
- vector of dimensionality dim- Returns:
- transformed vector of dimensionality dim
-
applyInverse
public double[] applyInverse(double[] v)
Apply the inverse transformation onto a vector- Parameters:
v
- vector of dimensionality dim- Returns:
- transformed vector of dimensionality dim
-
applyRelative
public double[] applyRelative(double[] v)
Apply the transformation onto a vector- Parameters:
v
- vector of dimensionality dim- Returns:
- transformed vector of dimensionality dim
-
applyRelativeInverse
public double[] applyRelativeInverse(double[] v)
Apply the inverse transformation onto a vector- Parameters:
v
- vector of dimensionality dim- Returns:
- transformed vector of dimensionality dim
-
-