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.String
ELEMENT_SEPARATOR
String used to separate elements in the matrix string representation.private static AffineTransformMatrix1D
IDENTITY_INSTANCE
Shared transform set to the identity matrix.private double
m00
Transform matrix entrym0,0
.private double
m01
Transform matrix entrym0,1
.private static java.lang.String
MATRIX_END
String used to end the transform matrix string representation.private static java.lang.String
MATRIX_START
String used to start the transform matrix string representation.private static int
NUM_ELEMENTS
The number of internal matrix elements.
-
Constructor Summary
Constructors Modifier Constructor Description private
AffineTransformMatrix1D(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 Vector1D
apply(Vector1D vec)
Vector1D.Unit
applyDirection(Vector1D vec)
Apply this transform to the given vector, ignoring translations and normalizing the result.Vector1D
applyVector(Vector1D vec)
Apply this transform to the given vector, ignoring translations.double
applyVectorX(double x)
Apply this transform to the given vector coordinate, ignoring translations, and return the transformed x value.double
applyX(double x)
Apply this transform to the given point coordinate and return the transformed x value.static AffineTransformMatrix1D
createScale(double factor)
Get a transform representing a scale operation.static AffineTransformMatrix1D
createScale(Vector1D factor)
Get a transform representing a scale operation.static AffineTransformMatrix1D
createTranslation(double x)
Get a transform representing the given translation.static AffineTransformMatrix1D
createTranslation(Vector1D translation)
Get a transform representing the given translation.double
determinant()
Get the determinant of the matrix.boolean
equals(java.lang.Object obj)
Return true if the given object is an instance ofAffineTransformMatrix1D
and all matrix element values are exactly equal.static AffineTransformMatrix1D
from(java.util.function.UnaryOperator<Vector1D> fn)
Construct a new transform representing the given function.int
hashCode()
static AffineTransformMatrix1D
identity()
Get the transform representing the identity matrix.AffineTransformMatrix1D
inverse()
Get an instance representing the inverse transform.AffineTransformMatrix1D
linear()
Return a matrix containing only the linear portion of this transform.AffineTransformMatrix1D
linearTranspose()
Return a matrix containing the transpose of the linear portion of this transform.AffineTransformMatrix1D
multiply(AffineTransformMatrix1D m)
Get a new transform created by multiplying this instance by the argument.private static AffineTransformMatrix1D
multiply(AffineTransformMatrix1D a, AffineTransformMatrix1D b)
Multiply two transform matrices together.static AffineTransformMatrix1D
of(double... arr)
Get a new transform with the given matrix elements.AffineTransformMatrix1D
premultiply(AffineTransformMatrix1D m)
Get a new transform created by multiplying the argument by this instance.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.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.double[]
toArray()
Return a 2 element array containing the variable elements from the internal transformation matrix.java.lang.String
toString()
AffineTransformMatrix1D
translate(double x)
Get a new transform containing the result of applying a translation logically after the transformation represented by the current instance.AffineTransformMatrix1D
translate(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
v
represents the difference between pointsp1
andp2
, thentransform.applyVector(v)
will represent the difference betweenp1
andp2
aftertransform
is 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:
applyDirection
in 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:
determinant
in 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:
linear
in 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:
linearTranspose
in 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
, whereA
is the current matrix andB
is 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
, whereA
is the current matrix andB
is 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
, whereA
is the current matrix andB
is 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
, whereA
is the current matrix andB
is 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 * M
whereA
is the current transform matrix andM
is the given transform matrix. In terms of transformations, applying the returned matrix is equivalent to applyingM
and 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 * A
whereA
is the current transform matrix andM
is the given transform matrix. In terms of transformations, applying the returned matrix is equivalent to applyingA
and 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:
inverse
in interfaceTransform<Vector1D>
- Specified by:
inverse
in 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:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
Return true if the given object is an instance ofAffineTransformMatrix1D
and all matrix element values are exactly equal.- Overrides:
equals
in 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:
toString
in 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
-
-