Class AffineTransformMatrix1D
- java.lang.Object
-
- org.apache.commons.geometry.euclidean.AbstractAffineTransformMatrix<Vector1D,AffineTransformMatrix1D>
-
- org.apache.commons.geometry.euclidean.oned.AffineTransformMatrix1D
-
- All Implemented Interfaces:
java.util.function.Function<Vector1D,Vector1D>,java.util.function.UnaryOperator<Vector1D>,Transform<Vector1D>,EuclideanTransform<Vector1D>
public final class AffineTransformMatrix1D extends AbstractAffineTransformMatrix<Vector1D,AffineTransformMatrix1D>
Class using a matrix to represent affine transformations in 1 dimensional Euclidean space.Instances of this class use a 2x2 matrix for all transform operations. The last row of this matrix is always set to the values
[0 1]and so is not stored. Hence, the methods in this class that accept or return arrays always use arrays containing 2 elements, instead of 4.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringELEMENT_SEPARATORString used to separate elements in the matrix string representation.private static AffineTransformMatrix1DIDENTITY_INSTANCEShared transform set to the identity matrix.private doublem00Transform matrix entrym0,0.private doublem01Transform matrix entrym0,1.private static java.lang.StringMATRIX_ENDString used to end the transform matrix string representation.private static java.lang.StringMATRIX_STARTString used to start the transform matrix string representation.private static intNUM_ELEMENTSThe number of internal matrix elements.
-
Constructor Summary
Constructors Modifier Constructor Description privateAffineTransformMatrix1D(double m00, double m01)Simple constructor; sets all internal matrix elements.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Vector1Dapply(Vector1D vec)Vector1D.UnitapplyDirection(Vector1D vec)Apply this transform to the given vector, ignoring translations and normalizing the result.Vector1DapplyVector(Vector1D vec)Apply this transform to the given vector, ignoring translations.doubleapplyVectorX(double x)Apply this transform to the given vector coordinate, ignoring translations, and return the transformed x value.doubleapplyX(double x)Apply this transform to the given point coordinate and return the transformed x value.static AffineTransformMatrix1DcreateScale(double factor)Get a transform representing a scale operation.static AffineTransformMatrix1DcreateScale(Vector1D factor)Get a transform representing a scale operation.static AffineTransformMatrix1DcreateTranslation(double x)Get a transform representing the given translation.static AffineTransformMatrix1DcreateTranslation(Vector1D translation)Get a transform representing the given translation.doubledeterminant()Get the determinant of the matrix.booleanequals(java.lang.Object obj)Return true if the given object is an instance ofAffineTransformMatrix1Dand all matrix element values are exactly equal.static AffineTransformMatrix1Dfrom(java.util.function.UnaryOperator<Vector1D> fn)Construct a new transform representing the given function.inthashCode()static AffineTransformMatrix1Didentity()Get the transform representing the identity matrix.AffineTransformMatrix1Dinverse()Get an instance representing the inverse transform.AffineTransformMatrix1Dlinear()Return a matrix containing only the linear portion of this transform.AffineTransformMatrix1DlinearTranspose()Return a matrix containing the transpose of the linear portion of this transform.AffineTransformMatrix1Dmultiply(AffineTransformMatrix1D m)Get a new transform created by multiplying this instance by the argument.private static AffineTransformMatrix1Dmultiply(AffineTransformMatrix1D a, AffineTransformMatrix1D b)Multiply two transform matrices together.static AffineTransformMatrix1Dof(double... arr)Get a new transform with the given matrix elements.AffineTransformMatrix1Dpremultiply(AffineTransformMatrix1D m)Get a new transform created by multiplying the argument by this instance.AffineTransformMatrix1Dscale(double x)Get a new transform containing the result of applying a scale operation logically after the transformation represented by the current instance.AffineTransformMatrix1Dscale(Vector1D scaleFactor)Get a new transform containing the result of applying a scale operation logically after the transformation represented by the current instance.double[]toArray()Return a 2 element array containing the variable elements from the internal transformation matrix.java.lang.StringtoString()AffineTransformMatrix1Dtranslate(double x)Get a new transform containing the result of applying a translation logically after the transformation represented by the current instance.AffineTransformMatrix1Dtranslate(Vector1D translation)Get a new transform containing the result of applying a translation logically after the transformation represented by the current instance.-
Methods inherited from class org.apache.commons.geometry.euclidean.AbstractAffineTransformMatrix
normalTransform, preservesOrientation
-
-
-
-
Field Detail
-
NUM_ELEMENTS
private static final int NUM_ELEMENTS
The number of internal matrix elements.- See Also:
- Constant Field Values
-
MATRIX_START
private static final java.lang.String MATRIX_START
String used to start the transform matrix string representation.- See Also:
- Constant Field Values
-
MATRIX_END
private static final java.lang.String MATRIX_END
String used to end the transform matrix string representation.- See Also:
- Constant Field Values
-
ELEMENT_SEPARATOR
private static final java.lang.String ELEMENT_SEPARATOR
String used to separate elements in the matrix string representation.- See Also:
- Constant Field Values
-
IDENTITY_INSTANCE
private static final AffineTransformMatrix1D IDENTITY_INSTANCE
Shared transform set to the identity matrix.
-
m00
private final double m00
Transform matrix entrym0,0.
-
m01
private final double m01
Transform matrix entrym0,1.
-
-
Method Detail
-
toArray
public double[] toArray()
Return a 2 element array containing the variable elements from the internal transformation matrix. The elements are in row-major order. The array indices map to the internal matrix as follows:[ arr[0], arr[1], 0 1 ]- Returns:
- 2 element array containing the variable elements from the internal transformation matrix
-
applyX
public double applyX(double x)
Apply this transform to the given point coordinate and return the transformed x value. The return value is equal to(x * m00) + m01.- Parameters:
x- x coordinate value- Returns:
- transformed x coordinate value
- See Also:
apply(Vector1D)
-
applyVector
public Vector1D applyVector(Vector1D vec)
Apply this transform to the given vector, ignoring translations.This method can be used to transform vector instances representing displacements between points. For example, if
vrepresents the difference between pointsp1andp2, thentransform.applyVector(v)will represent the difference betweenp1andp2aftertransformis applied.- Parameters:
vec- the vector to transform- Returns:
- the new, transformed vector
- See Also:
applyDirection(Vector1D)
-
applyVectorX
public double applyVectorX(double x)
Apply this transform to the given vector coordinate, ignoring translations, and return the transformed x value. The return value is equal tox * m00.- Parameters:
x- x coordinate value- Returns:
- transformed x coordinate value
- See Also:
applyVector(Vector1D)
-
applyDirection
public Vector1D.Unit applyDirection(Vector1D vec)
Apply this transform to the given vector, ignoring translations and normalizing the result. This is equivalent totransform.applyVector(vec).normalize()but without the intermediate vector instance.- Specified by:
applyDirectionin classAbstractAffineTransformMatrix<Vector1D,AffineTransformMatrix1D>- Parameters:
vec- the vector to transform- Returns:
- the new, transformed unit vector
- See Also:
applyVector(Vector1D)
-
determinant
public double determinant()
Get the determinant of the matrix.- Specified by:
determinantin classAbstractAffineTransformMatrix<Vector1D,AffineTransformMatrix1D>- Returns:
- the determinant of the matrix
-
linear
public AffineTransformMatrix1D linear()
Return a matrix containing only the linear portion of this transform. The returned instance contains the same matrix elements as this instance but with the translation component set to zero.Example
[ a, b ] [ a, 0 ] [ 0, 1 ] → [ 0, 1 ]- Specified by:
linearin classAbstractAffineTransformMatrix<Vector1D,AffineTransformMatrix1D>- Returns:
- a matrix containing only the linear portion of this transform
-
linearTranspose
public AffineTransformMatrix1D linearTranspose()
Return a matrix containing the transpose of the linear portion of this transform. The returned instance is linear, meaning it has a translation component of zero.In the one dimensional case, this is exactly the same as
linear().Example
[ a, b ] [ a, 0 ] [ 0, 1 ] → [ 0, 1 ]- Specified by:
linearTransposein classAbstractAffineTransformMatrix<Vector1D,AffineTransformMatrix1D>- Returns:
- a matrix containing the transpose of the linear portion of this transform
-
translate
public AffineTransformMatrix1D translate(Vector1D translation)
Get a new transform containing the result of applying a translation logically after the transformation represented by the current instance. This is achieved by creating a new translation transform and pre-multiplying it with the current instance. In other words, the returned transform contains the matrixB * A, whereAis the current matrix andBis the matrix representing the given translation.- Parameters:
translation- vector containing the translation values for each axis- Returns:
- a new transform containing the result of applying a translation to the current instance
-
translate
public AffineTransformMatrix1D translate(double x)
Get a new transform containing the result of applying a translation logically after the transformation represented by the current instance. This is achieved by creating a new translation transform and pre-multiplying it with the current instance. In other words, the returned transform contains the matrixB * A, whereAis the current matrix andBis the matrix representing the given translation.- Parameters:
x- translation in the x direction- Returns:
- a new transform containing the result of applying a translation to the current instance
-
scale
public AffineTransformMatrix1D scale(Vector1D scaleFactor)
Get a new transform containing the result of applying a scale operation logically after the transformation represented by the current instance. This is achieved by creating a new scale transform and pre-multiplying it with the current instance. In other words, the returned transform contains the matrixB * A, whereAis the current matrix andBis the matrix representing the given scale operation.- Parameters:
scaleFactor- vector containing scale factors for each axis- Returns:
- a new transform containing the result of applying a scale operation to the current instance
-
scale
public AffineTransformMatrix1D scale(double x)
Get a new transform containing the result of applying a scale operation logically after the transformation represented by the current instance. This is achieved by creating a new scale transform and pre-multiplying it with the current instance. In other words, the returned transform contains the matrixB * A, whereAis the current matrix andBis the matrix representing the given scale operation.- Parameters:
x- scale factor- Returns:
- a new transform containing the result of applying a scale operation to the current instance
-
multiply
public AffineTransformMatrix1D multiply(AffineTransformMatrix1D m)
Get a new transform created by multiplying this instance by the argument. This is equivalent to the expressionA * MwhereAis the current transform matrix andMis the given transform matrix. In terms of transformations, applying the returned matrix is equivalent to applyingMand then applyingA. In other words, the rightmost transform is applied first.- Parameters:
m- the transform to multiply with- Returns:
- the result of multiplying the current instance by the given transform matrix
-
premultiply
public AffineTransformMatrix1D premultiply(AffineTransformMatrix1D m)
Get a new transform created by multiplying the argument by this instance. This is equivalent to the expressionM * AwhereAis the current transform matrix andMis the given transform matrix. In terms of transformations, applying the returned matrix is equivalent to applyingAand then applyingM. In other words, the rightmost transform is applied first.- Parameters:
m- the transform to multiply with- Returns:
- the result of multiplying the given transform matrix by the current instance
-
inverse
public AffineTransformMatrix1D inverse()
Get an instance representing the inverse transform.- Specified by:
inversein interfaceTransform<Vector1D>- Specified by:
inversein classAbstractAffineTransformMatrix<Vector1D,AffineTransformMatrix1D>- Returns:
- an instance representing the inverse transform
- Throws:
java.lang.IllegalStateException- if the matrix cannot be inverted
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
Return true if the given object is an instance ofAffineTransformMatrix1Dand all matrix element values are exactly equal.- Overrides:
equalsin classjava.lang.Object- Parameters:
obj- object to test for equality with the current instance- Returns:
- true if all transform matrix elements are exactly equal; otherwise false
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
of
public static AffineTransformMatrix1D of(double... arr)
Get a new transform with the given matrix elements. The array must contain 2 elements. The first element in the array represents the scale factor for the transform and the second represents the translation.- Parameters:
arr- 2-element array containing values for the variable entries in the transform matrix- Returns:
- a new transform initialized with the given matrix values
- Throws:
java.lang.IllegalArgumentException- if the array does not have 2 elements
-
from
public static AffineTransformMatrix1D from(java.util.function.UnaryOperator<Vector1D> fn)
Construct a new transform representing the given function. The function is sampled at the points zero and one and a matrix is created to perform the transformation.- Parameters:
fn- function to create a transform matrix from- Returns:
- a transform matrix representing the given function
- Throws:
java.lang.IllegalArgumentException- if the given function does not represent a valid affine transform
-
identity
public static AffineTransformMatrix1D identity()
Get the transform representing the identity matrix. This transform does not modify point or vector values when applied.- Returns:
- transform representing the identity matrix
-
createTranslation
public static AffineTransformMatrix1D createTranslation(Vector1D translation)
Get a transform representing the given translation.- Parameters:
translation- vector containing translation values for each axis- Returns:
- a new transform representing the given translation
-
createTranslation
public static AffineTransformMatrix1D createTranslation(double x)
Get a transform representing the given translation.- Parameters:
x- translation in the x direction- Returns:
- a new transform representing the given translation
-
createScale
public static AffineTransformMatrix1D createScale(Vector1D factor)
Get a transform representing a scale operation.- Parameters:
factor- vector containing the scale factor- Returns:
- a new transform representing a scale operation
-
createScale
public static AffineTransformMatrix1D createScale(double factor)
Get a transform representing a scale operation.- Parameters:
factor- scale factor- Returns:
- a new transform representing a scale operation
-
multiply
private static AffineTransformMatrix1D multiply(AffineTransformMatrix1D a, AffineTransformMatrix1D b)
Multiply two transform matrices together.- Parameters:
a- first transformb- second transform- Returns:
- the transform computed as
a x b
-
-