public final class AffineTransformMatrix2D extends AbstractAffineTransformMatrix<Vector2D,AffineTransformMatrix2D>
Instances of this class use a 3x3 matrix for all transform operations.
The last row of this matrix is always set to the values [0 0 1]
and so
is not stored. Hence, the methods in this class that accept or return arrays always
use arrays containing 6 elements, instead of 9.
Modifier and Type | Method and Description |
---|---|
Vector2D |
apply(Vector2D pt)
Apply this transform to the given point, returning the result as a new instance.
|
Vector2D.Unit |
applyDirection(Vector2D vec)
Apply this transform to the given vector, ignoring translations and normalizing the
result.
|
Vector2D |
applyVector(Vector2D vec)
Apply this transform to the given vector, ignoring translations.
|
double |
applyVectorX(double x,
double y)
Apply this transform to the given vector coordinates, ignoring translations, and
return the transformed x value.
|
double |
applyVectorY(double x,
double y)
Apply this transform to the given vector coordinates, ignoring translations, and
return the transformed y value.
|
double |
applyX(double x,
double y)
Apply this transform to the given point coordinates and return the transformed
x value.
|
double |
applyY(double x,
double y)
Apply this transform to the given point coordinates and return the transformed
y value.
|
static AffineTransformMatrix2D |
createRotation(double angle)
Create a transform representing a counterclockwise rotation of
angle
radians around the origin. |
static AffineTransformMatrix2D |
createRotation(Vector2D center,
double angle)
Create a transform representing a counterclockwise rotation of
angle
radians around the given center point. |
static AffineTransformMatrix2D |
createRotation(Vector2D center,
Rotation2D rotation)
Create a transform representing a counterclockwise rotation around the given center point.
|
static AffineTransformMatrix2D |
createScale(double factor)
Create a transform representing a scale operation with the given scale factor applied to all axes.
|
static AffineTransformMatrix2D |
createScale(double x,
double y)
Create a transform representing a scale operation.
|
static AffineTransformMatrix2D |
createScale(Vector2D factors)
Create a transform representing a scale operation.
|
static AffineTransformMatrix2D |
createShear(double shx,
double shy)
Create a transform representing a shear operation.
|
static AffineTransformMatrix2D |
createTranslation(double x,
double y)
Create a transform representing the given translation.
|
static AffineTransformMatrix2D |
createTranslation(Vector2D translation)
Create a transform representing the given translation.
|
double |
determinant()
Get the determinant of the matrix.
|
boolean |
equals(Object obj)
Return true if the given object is an instance of
AffineTransformMatrix2D
and all matrix element values are exactly equal. |
static AffineTransformMatrix2D |
from(UnaryOperator<Vector2D> fn)
Construct a new transform representing the given function.
|
static AffineTransformMatrix2D |
fromColumnVectors(Vector2D u,
Vector2D v)
Get a new transform create from the given column vectors.
|
static AffineTransformMatrix2D |
fromColumnVectors(Vector2D u,
Vector2D v,
Vector2D t)
Get a new transform created from the given column vectors.
|
int |
hashCode() |
static AffineTransformMatrix2D |
identity()
Get the transform representing the identity matrix.
|
AffineTransformMatrix2D |
inverse() |
AffineTransformMatrix2D |
linear()
Return a matrix containing only the linear portion of this transform.
|
AffineTransformMatrix2D |
linearTranspose()
Return a matrix containing the transpose of the linear portion of this transform.
|
AffineTransformMatrix2D |
multiply(AffineTransformMatrix2D m)
Get a new transform created by multiplying this instance by the argument.
|
static AffineTransformMatrix2D |
of(double... arr)
Get a new transform with the given matrix elements.
|
AffineTransformMatrix2D |
premultiply(AffineTransformMatrix2D m)
Get a new transform created by multiplying the argument by this instance.
|
AffineTransformMatrix2D |
rotate(double angle)
Apply a counterclockwise rotation to the current instance, returning the result as a
new transform.
|
AffineTransformMatrix2D |
rotate(Rotation2D rotation)
Apply a counterclockwise rotation to the current instance, returning the result as a
new transform.
|
AffineTransformMatrix2D |
rotate(Vector2D center,
double angle)
Apply a counterclockwise rotation about the given center point to the current instance,
returning the result as a new transform.
|
AffineTransformMatrix2D |
rotate(Vector2D center,
Rotation2D rotation)
Apply a counterclockwise rotation about the given center point to the current instance,
returning the result as a new transform.
|
AffineTransformMatrix2D |
scale(double factor)
Apply a scale operation to the current instance, returning the result as a new transform.
|
AffineTransformMatrix2D |
scale(double x,
double y)
Apply a scale operation to the current instance, returning the result as a new transform.
|
AffineTransformMatrix2D |
scale(Vector2D scaleFactors)
Apply a scale operation to the current instance, returning the result as a new transform.
|
AffineTransformMatrix2D |
shear(double shx,
double shy)
Apply a shear to the current instance, returning the result as a new transform.
|
double[] |
toArray()
Return a 6 element array containing the variable elements from the
internal transformation matrix.
|
String |
toString() |
AffineTransformMatrix2D |
translate(double x,
double y)
Apply a translation to the current instance, returning the result as a new transform.
|
AffineTransformMatrix2D |
translate(Vector2D translation)
Apply a translation to the current instance, returning the result as a new transform.
|
normalTransform, preservesOrientation
public double[] toArray()
[ arr[0], arr[1], arr[2], arr[3], arr[4], arr[5], 0 0 1 ]
public Vector2D apply(Vector2D pt)
The transformed point is computed by creating a 3-element column vector from the
coordinates in the input and setting the last element to 1. This is then multiplied with the
3x3 transform matrix to produce the transformed point. The 1
in the last position
is ignored.
[ m00 m01 m02 ] [ x ] [ x'] [ m10 m11 m12 ] * [ y ] = [ y'] [ 0 0 1 ] [ 1 ] [ 1 ]
public double applyX(double x, double y)
(x * m00) + (y * m01) + m02
.x
- x coordinate valuey
- y coordinate valueapply(Vector2D)
public double applyY(double x, double y)
(x * m10) + (y * m11) + m12
.x
- x coordinate valuey
- y coordinate valueapply(Vector2D)
public Vector2D applyVector(Vector2D vec)
This method can be used to transform vector instances representing displacements between points.
For example, if v
represents the difference between points p1
and p2
,
then transform.applyVector(v)
will represent the difference between p1
and p2
after transform
is applied.
The transformed vector is computed by creating a 3-element column vector from the
coordinates in the input and setting the last element to 0. This is then multiplied with the
3x3 transform matrix to produce the transformed vector. The 0
in the last position
is ignored.
[ m00 m01 m02 ] [ x ] [ x'] [ m10 m11 m12 ] * [ y ] = [ y'] [ 0 0 1 ] [ 0 ] [ 0 ]
vec
- the vector to transformapplyDirection(Vector2D)
public double applyVectorX(double x, double y)
(x * m00) + (y * m01)
.x
- x coordinate valuey
- y coordinate valueapplyVector(Vector2D)
public double applyVectorY(double x, double y)
(x * m10) + (y * m11)
.x
- x coordinate valuey
- y coordinate valueapplyVector(Vector2D)
public Vector2D.Unit applyDirection(Vector2D vec)
transform.applyVector(vec).normalize()
but without
the intermediate vector instance.applyDirection
in class AbstractAffineTransformMatrix<Vector2D,AffineTransformMatrix2D>
vec
- the vector to transformapplyVector(Vector2D)
public double determinant()
determinant
in class AbstractAffineTransformMatrix<Vector2D,AffineTransformMatrix2D>
public AffineTransformMatrix2D linear()
Example
[ a, b, c ] [ a, b, 0 ] [ d, e, f ] → [ d, e, 0 ] [ 0, 0, 1 ] [ 0, 0, 1 ]
linear
in class AbstractAffineTransformMatrix<Vector2D,AffineTransformMatrix2D>
public AffineTransformMatrix2D linearTranspose()
Example
[ a, b, c ] [ a, d, 0 ] [ d, e, f ] → [ b, e, 0 ] [ 0, 0, 1 ] [ 0, 0, 1 ]
linearTranspose
in class AbstractAffineTransformMatrix<Vector2D,AffineTransformMatrix2D>
public AffineTransformMatrix2D translate(Vector2D translation)
translation
- vector containing the translation values for each axispublic AffineTransformMatrix2D translate(double x, double y)
x
- translation in the x directiony
- translation in the y directionpublic AffineTransformMatrix2D scale(double factor)
factor
- the scale factor to apply to all axespublic AffineTransformMatrix2D scale(Vector2D scaleFactors)
scaleFactors
- vector containing scale factors for each axispublic AffineTransformMatrix2D scale(double x, double y)
x
- scale factor for the x axisy
- scale factor for the y axispublic AffineTransformMatrix2D rotate(double angle)
angle
- the angle of counterclockwise rotation in radiansRotation2D.of(double)
public AffineTransformMatrix2D rotate(Rotation2D rotation)
rotation
- the rotation to applypublic AffineTransformMatrix2D rotate(Vector2D center, double angle)
center
- the center of rotationangle
- the angle of counterclockwise rotation in radianspublic AffineTransformMatrix2D rotate(Vector2D center, Rotation2D rotation)
center
- the center of rotationrotation
- the rotation to applypublic AffineTransformMatrix2D shear(double shx, double shy)
shx
- multiplier by which coordinates are shifted along the positive x-axis as a factor of their
y coordinate; a value of 0 indicates no shift along the x-axisshy
- multiplier by which coordinates are shifted along the positive y-axis as a factor of their
x coordinate; a value of 0 indicates no shift along the y-axispublic AffineTransformMatrix2D multiply(AffineTransformMatrix2D m)
A * M
where A
is the
current transform matrix and M
is the given transform matrix. In
terms of transformations, applying the returned matrix is equivalent to
applying M
and then applying A
. In other words,
the rightmost transform is applied first.m
- the transform to multiply withpublic AffineTransformMatrix2D premultiply(AffineTransformMatrix2D m)
M * A
where A
is the
current transform matrix and M
is the given transform matrix. In
terms of transformations, applying the returned matrix is equivalent to
applying A
and then applying M
. In other words,
the rightmost transform is applied first.m
- the transform to multiply withpublic AffineTransformMatrix2D inverse()
inverse
in interface Transform<Vector2D>
inverse
in class AbstractAffineTransformMatrix<Vector2D,AffineTransformMatrix2D>
IllegalStateException
- if the matrix cannot be invertedpublic boolean equals(Object obj)
AffineTransformMatrix2D
and all matrix element values are exactly equal.public static AffineTransformMatrix2D of(double... arr)
arr
- 6-element array containing values for the variable entries in the
transform matrixIllegalArgumentException
- if the array does not have 6 elementspublic static AffineTransformMatrix2D from(UnaryOperator<Vector2D> fn)
fn
- function to create a transform matrix fromIllegalArgumentException
- if the given function does not represent a valid
affine transformpublic static AffineTransformMatrix2D fromColumnVectors(Vector2D u, Vector2D v)
u
- first column vector; this corresponds to the first basis vector
in the coordinate framev
- second column vector; this corresponds to the second basis vector
in the coordinate framepublic static AffineTransformMatrix2D fromColumnVectors(Vector2D u, Vector2D v, Vector2D t)
u
- first column vector; this corresponds to the first basis vector
in the coordinate framev
- second column vector; this corresponds to the second basis vector
in the coordinate framet
- third column vector; this corresponds to the translation of the transformpublic static AffineTransformMatrix2D identity()
public static AffineTransformMatrix2D createTranslation(Vector2D translation)
translation
- vector containing translation values for each axispublic static AffineTransformMatrix2D createTranslation(double x, double y)
x
- translation in the x directiony
- translation in the y directionpublic static AffineTransformMatrix2D createScale(double factor)
factor
- scale factor to apply to all axespublic static AffineTransformMatrix2D createScale(Vector2D factors)
factors
- vector containing scale factors for each axispublic static AffineTransformMatrix2D createScale(double x, double y)
x
- scale factor for the x axisy
- scale factor for the y axispublic static AffineTransformMatrix2D createRotation(double angle)
angle
radians around the origin.angle
- the angle of rotation in radiansRotation2D.toMatrix()
public static AffineTransformMatrix2D createRotation(Vector2D center, double angle)
angle
radians around the given center point. This is accomplished by translating the center point
to the origin, applying the rotation, and then translating back.center
- the center of rotationangle
- the angle of rotation in radianspublic static AffineTransformMatrix2D createRotation(Vector2D center, Rotation2D rotation)
center
- the center of rotationrotation
- the rotation to applypublic static AffineTransformMatrix2D createShear(double shx, double shy)
[ 1, shx, 0 ] [ shy, 1, 0 ] [ 0, 0, 0 ]
shx
- multiplier by which coordinates are shifted along the positive x-axis as a factor of their
y coordinate; a value of 0 indicates no shift along the x-axisshy
- multiplier by which coordinates are shifted along the positive y-axis as a factor of their
x coordinate; a value of 0 indicates no shift along the y-axisCopyright © 2016–2021 The Apache Software Foundation. All rights reserved.