Class AffineTransformMatrix1D
java.lang.Object
org.apache.commons.geometry.euclidean.AbstractAffineTransformMatrix<Vector1D,AffineTransformMatrix1D>
org.apache.commons.geometry.euclidean.oned.AffineTransformMatrix1D
- All Implemented Interfaces:
Function<Vector1D,
,Vector1D> 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
FieldsModifier and TypeFieldDescriptionprivate static final String
String used to separate elements in the matrix string representation.private static final AffineTransformMatrix1D
Shared transform set to the identity matrix.private final double
Transform matrix entrym0,0
.private final double
Transform matrix entrym0,1
.private static final String
String used to end the transform matrix string representation.private static final String
String used to start the transform matrix string representation.private static final int
The number of internal matrix elements. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
AffineTransformMatrix1D
(double m00, double m01) Simple constructor; sets all internal matrix elements. -
Method Summary
Modifier and TypeMethodDescriptionapplyDirection
(Vector1D vec) Apply this transform to the given vector, ignoring translations and normalizing the result.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
Get the determinant of the matrix.boolean
Return true if the given object is an instance ofAffineTransformMatrix1D
and all matrix element values are exactly equal.static AffineTransformMatrix1D
from
(UnaryOperator<Vector1D> fn) Construct a new transform representing the given function.int
hashCode()
static AffineTransformMatrix1D
identity()
Get the transform representing the identity matrix.inverse()
Get an instance representing the inverse transform.linear()
Return a matrix containing only the linear portion of this transform.Return a matrix containing the transpose of the linear portion of this transform.Get a new transform created by multiplying this instance by the argument.private static AffineTransformMatrix1D
Multiply two transform matrices together.static AffineTransformMatrix1D
of
(double... arr) Get a new transform with the given matrix elements.Get a new transform created by multiplying the argument by this instance.scale
(double x) Get a new transform containing the result of applying a scale operation logically after the transformation represented by the current instance.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.toString()
translate
(double x) Get a new transform containing the result of applying a translation logically after the transformation represented by the current instance.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 Details
-
NUM_ELEMENTS
private static final int NUM_ELEMENTSThe number of internal matrix elements.- See Also:
-
MATRIX_START
String used to start the transform matrix string representation.- See Also:
-
MATRIX_END
String used to end the transform matrix string representation.- See Also:
-
ELEMENT_SEPARATOR
String used to separate elements in the matrix string representation.- See Also:
-
IDENTITY_INSTANCE
Shared transform set to the identity matrix. -
m00
private final double m00Transform matrix entrym0,0
. -
m01
private final double m01Transform matrix entrym0,1
.
-
-
Constructor Details
-
AffineTransformMatrix1D
private AffineTransformMatrix1D(double m00, double m01) Simple constructor; sets all internal matrix elements.- Parameters:
m00
- matrix entrym0,0
m01
- matrix entrym0,1
-
-
Method Details
-
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
-
apply
-
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:
-
applyVector
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:
-
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:
-
applyDirection
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:
-
determinant
public double determinant()Get the determinant of the matrix.- Specified by:
determinant
in classAbstractAffineTransformMatrix<Vector1D,
AffineTransformMatrix1D> - Returns:
- the determinant of the matrix
-
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
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
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
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
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
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
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
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
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:
IllegalStateException
- if the matrix cannot be inverted
-
hashCode
public int hashCode() -
equals
Return true if the given object is an instance ofAffineTransformMatrix1D
and all matrix element values are exactly equal. -
toString
-
of
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:
IllegalArgumentException
- if the array does not have 2 elements
-
from
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:
IllegalArgumentException
- if the given function does not represent a valid affine transform
-
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
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
Get a transform representing the given translation.- Parameters:
x
- translation in the x direction- Returns:
- a new transform representing the given translation
-
createScale
Get a transform representing a scale operation.- Parameters:
factor
- vector containing the scale factor- Returns:
- a new transform representing a scale operation
-
createScale
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
-