- java.lang.Object
-
- org.arakhne.afc.math.matrix.Matrix3d
-
- org.arakhne.afc.math.geometry.d2.Transform2D
-
- All Implemented Interfaces:
Serializable
,Cloneable
public class Transform2D extends Matrix3d
A 2D transformation. Is represented internally as a 3x3 floating point matrix. The mathematical representation is row major, as in traditional matrix mathematics.The transformation matrix is:
| cos(theta) | -+sin(theta) | Tx | | -+sin(theta) | cos(theta) | Ty | | 0 | 0 | 1 |
- Version:
- 17.0 2020-01-04 14:41:43
- Author:
- Stéphane GALLAND
- See Also:
- Serialized Form
- Maven Group Id:
- org.arakhne.afc.core
- Maven Artifact Id:
- mathgeom
-
-
Constructor Summary
Constructors Constructor Description Transform2D()
Constructs a new Transform2D object and sets it to the identity transformation.Transform2D(double m00, double m01, double m02, double m10, double m11, double m12)
Constructs and initializes a Matrix3f from the specified nine values.Transform2D(Transform2D tranform)
Constructs a new Transform2D object and initializes it from the specified transform.Transform2D(Matrix3d matrix)
Constructor by copy.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Transform2D
clone()
Creates a new object of the same class as this object.Transform2D
createInverse()
Returns anTransform2D
object representing the inverse transformation.double
getRotation()
Performs an SVD normalization of this matrix to calculate and return the rotation angle.double
getScale()
Performs an SVD normalization of this matrix to calculate and return the uniform scale factor.protected void
getScaleRotate2x2(double[] scales, double[] rots)
Perform SVD on the 2x2 matrix containing the rotation and scaling factors.void
getScaleVector(Tuple2D<?> scale)
Performs an SVD normalization of this matrix to calculate and return the scale factors for X and Y axess.double
getScaleX()
Performs an SVD normalization of this matrix to calculate and return the scale factor for X axis.double
getScaleY()
Performs an SVD normalization of this matrix to calculate and return the scale factor for Y axis.void
getTranslationVector(Tuple2D<?> translation)
Replies the translation.double
getTranslationX()
Replies the X translation.double
getTranslationY()
Replies the Y translation.void
invert()
Invert this transformation.void
invert(Matrix3d matrix)
Invert this transformation.void
makeRotationMatrix(double angle)
Sets the value of this matrix to a counter clockwise rotation about the x axis, and no translationvoid
makeScaleMatrix(double scaleX, double scaleY)
Sets the value of this matrix to the given scaling, without rotation.void
makeTranslationMatrix(double dx, double dy)
Sets the value of this matrix to the given translation, without rotation.void
rotate(double theta)
Rotate the object (theta).void
scale(double scale)
Concatenates this transform with a scaling transformation.void
scale(double scaleX, double scaleY)
Concatenates this transform with a scaling transformation.void
scale(Tuple2D<?> tuple)
Concatenates this transform with a scaling transformation.void
set(double m00, double m01, double m02, double m10, double m11, double m12)
Set the components of the transformation.void
setRotation(double angle)
Change the rotation of this matrix.void
setScale(double scaleX, double scaleY)
Change the scale of this matrix.void
setScale(Tuple2D<?> tuple)
Set the scale.void
setTranslation(double x, double y)
Set the position.void
setTranslation(Tuple2D<?> translation)
Set the position.void
shear(double shearX, double shearY)
Concatenates this transform with a shearing transformation.void
shear(Tuple2D<?> shear)
Concatenates this transform with a shearing transformation.void
transform(Tuple2D<?> tuple)
Multiply this matrix by the tuple t and place the result back into the tuple (t = this*t).void
transform(Tuple2D<?> tuple, Tuple2D<?> result)
Multiply this matrix by the tuple t and and place the result into the tuple "result".void
translate(double dx, double dy)
Translate the position.void
translate(Vector2D<?,?> translation)
Translate the position.-
Methods inherited from class org.arakhne.afc.math.matrix.Matrix3d
$bang, $div, $minus, $minus, $minus, $plus, $plus, $times, $times, add, add, add, add, computeSVD, cov, cov, cov, determinant, eigenVectorsOfSymmetricMatrix, epsilonEquals, equals, equals, getColumn, getColumn, getElement, getM00, getM01, getM02, getM10, getM11, getM12, getM20, getM21, getM22, getRow, getRow, hashCode, isIdentity, isSymmetric, mul, mul, mul, mul, mul, mulNormalize, mulNormalize, mulTransposeBoth, mulTransposeLeft, mulTransposeLeft, mulTransposeRight, negate, negate, normalize, normalize, normalizeCP, normalizeCP, operator_add, operator_add, operator_divide, operator_minus, operator_minus, operator_minus, operator_moinsMoins, operator_multiply, operator_multiply, operator_not, operator_plus, operator_plus, operator_plusPlus, operator_remove, operator_remove, set, set, set, setColumn, setColumn, setColumn, setDiagonal, setElement, setIdentity, setM00, setM01, setM02, setM10, setM11, setM12, setM20, setM21, setM22, setRow, setRow, setRow, setZero, sub, sub, toString, transpose, transpose
-
-
-
-
Field Detail
-
IDENTITY
public static final Transform2D IDENTITY
This is the identifity transformation.
-
-
Constructor Detail
-
Transform2D
public Transform2D()
Constructs a new Transform2D object and sets it to the identity transformation.
-
Transform2D
public Transform2D(Transform2D tranform)
Constructs a new Transform2D object and initializes it from the specified transform.- Parameters:
tranform
- the transformation to copy.
-
Transform2D
public Transform2D(Matrix3d matrix)
Constructor by copy.- Parameters:
matrix
- the matrix to copy.
-
Transform2D
public Transform2D(double m00, double m01, double m02, double m10, double m11, double m12)
Constructs and initializes a Matrix3f from the specified nine values.- Parameters:
m00
- the [0][0] elementm01
- the [0][1] elementm02
- the [0][2] elementm10
- the [1][0] elementm11
- the [1][1] elementm12
- the [1][2] element
-
-
Method Detail
-
clone
@Pure public Transform2D clone()
Description copied from class:Matrix3d
Creates a new object of the same class as this object.
-
setTranslation
public void setTranslation(double x, double y)
Set the position.This function changes only the elements of the matrix related to the translation (m02, m12). The scaling and the shearing are not changed.
After a call to this function, the matrix will contains (? means any value):
[ ? ? x ] [ ? ? y ] [ ? ? ? ]
- Parameters:
x
- x translation.y
- y translation.- See Also:
makeTranslationMatrix(double, double)
-
setTranslation
public void setTranslation(Tuple2D<?> translation)
Set the position.This function changes only the elements of the matrix related to the translation (m02, m12). The scaling and the shearing are not changed.
After a call to this function, the matrix will contains (? means any value):
[ ? ? t.x ] [ ? ? t.y ] [ ? ? ? ]
- Parameters:
translation
- the translation.- See Also:
makeTranslationMatrix(double, double)
-
translate
public void translate(double dx, double dy)
Translate the position.This function is equivalent to:
this = this * [ 1 0 dx ] [ 0 1 dy ] [ 0 0 1 ]
- Parameters:
dx
- the x translationdy
- the y translation
-
translate
public void translate(Vector2D<?,?> translation)
Translate the position.This function is equivalent to:
this = this * [ 1 0 t.x ] [ 0 1 t.y ] [ 0 0 1 ]
- Parameters:
translation
- the translation.
-
getTranslationX
@Pure public double getTranslationX()
Replies the X translation.- Returns:
- the amount
-
getTranslationY
@Pure public double getTranslationY()
Replies the Y translation.- Returns:
- the amount
-
getTranslationVector
@Pure public void getTranslationVector(Tuple2D<?> translation)
Replies the translation.- Parameters:
translation
- the vector to set with the translation component.
-
rotate
public void rotate(double theta)
Rotate the object (theta).This function is equivalent to:
this = this * [ cos(theta) -sin(theta) 0 ] [ sin(theta) cos(theta) 0 ] [ 0 0 1 ]
- Parameters:
theta
- the rotation angle, in radians.
-
getScaleRotate2x2
protected void getScaleRotate2x2(double[] scales, double[] rots)
Perform SVD on the 2x2 matrix containing the rotation and scaling factors.- Parameters:
scales
- the scaling factors.rots
- the rotation factors.
-
getRotation
@Pure public double getRotation()
Performs an SVD normalization of this matrix to calculate and return the rotation angle.- Returns:
- the rotation angle of this matrix. The value is in [-PI; PI]
-
setRotation
public void setRotation(double angle)
Change the rotation of this matrix. Performs an SVD normalization of this matrix for determining and preserving the scaling.- Parameters:
angle
- the rotation angle.
-
scale
public void scale(double scaleX, double scaleY)
Concatenates this transform with a scaling transformation.This function is equivalent to:
this = this * [ sx 0 0 ] [ 0 sy 0 ] [ 0 0 1 ]
- Parameters:
scaleX
- scaling along x axis.scaleY
- scaling along y axis.
-
scale
public void scale(Tuple2D<?> tuple)
Concatenates this transform with a scaling transformation.This function is equivalent to:
this = this * [ t.x 0 0 ] [ 0 t.y 0 ] [ 0 0 1 ]
- Parameters:
tuple
- the scaling factors.
-
scale
public void scale(double scale)
Concatenates this transform with a scaling transformation.This function is equivalent to:
this = this * [ s 0 0 ] [ 0 s 0 ] [ 0 0 1 ]
- Parameters:
scale
- the scaling factor.
-
getScale
@Pure public double getScale()
Performs an SVD normalization of this matrix to calculate and return the uniform scale factor. If the matrix has non-uniform scale factors, the largest of the x, y scale factors will be returned.- Returns:
- the scale factor of this matrix.
-
getScaleX
@Pure public double getScaleX()
Performs an SVD normalization of this matrix to calculate and return the scale factor for X axis.- Returns:
- the x scale factor.
-
getScaleY
@Pure public double getScaleY()
Performs an SVD normalization of this matrix to calculate and return the scale factor for Y axis.- Returns:
- the y scale factor.
-
getScaleVector
@Pure public void getScaleVector(Tuple2D<?> scale)
Performs an SVD normalization of this matrix to calculate and return the scale factors for X and Y axess.- Parameters:
scale
- the tuple to set.
-
setScale
public void setScale(double scaleX, double scaleY)
Change the scale of this matrix. Performs an SVD normalization of this matrix for determining and preserving the rotation.- Parameters:
scaleX
- the scaling factor along x axis.scaleY
- the scaling factor along y axis.- See Also:
makeScaleMatrix(double, double)
-
setScale
public void setScale(Tuple2D<?> tuple)
Set the scale.This function changes only the elements of the matrix related to the scaling (m00, m11). The shearing and the translation are not changed. The rotation is lost.
After a call to this function, the matrix will contains (? means any value):
[ t.x ? ? ] [ ? t.y ? ] [ ? ? ? ]
- Parameters:
tuple
- the scaling factors.- See Also:
makeScaleMatrix(double, double)
-
shear
public void shear(double shearX, double shearY)
Concatenates this transform with a shearing transformation.This function is equivalent to:
this = this * [ 1 shx 0 ] [ shy 1 0 ] [ 0 0 1 ]
- Parameters:
shearX
- the shearing factory along x axis.shearY
- the shearing factory along y axis.
-
shear
public void shear(Tuple2D<?> shear)
Concatenates this transform with a shearing transformation.This function is equivalent to:
this = this * [ 1 shx 0 ] [ shy 1 0 ] [ 0 0 1 ]
- Parameters:
shear
- the shear factors.
-
makeRotationMatrix
public void makeRotationMatrix(double angle)
Sets the value of this matrix to a counter clockwise rotation about the x axis, and no translationThis function changes all the elements of the matrix, icluding the translation.
After a call to this function, the matrix will contains (? means any value):
[ cos(theta) -sin(theta) 0 ] [ sin(theta) cos(theta) 0 ] [ 0 0 1 ]
- Parameters:
angle
- the angle to rotate about the X axis in radians- See Also:
setRotation(double)
-
makeTranslationMatrix
public void makeTranslationMatrix(double dx, double dy)
Sets the value of this matrix to the given translation, without rotation.This function changes all the elements of the matrix including the scaling and the shearing.
After a call to this function, the matrix will contains (? means any value):
[ 1 0 x ] [ 0 1 y ] [ 0 0 1 ]
- Parameters:
dx
- is the translation along X.dy
- is the translation along Y.- See Also:
setTranslation(double, double)
,setTranslation(Tuple2D)
-
makeScaleMatrix
public void makeScaleMatrix(double scaleX, double scaleY)
Sets the value of this matrix to the given scaling, without rotation.This function changes all the elements of the matrix, including the shearing and the translation.
After a call to this function, the matrix will contains (? means any value):
[ sx 0 0 ] [ 0 sy 0 ] [ 0 0 1 ]
- Parameters:
scaleX
- is the scaling along X.scaleY
- is the scaling along Y.- See Also:
setScale(double, double)
,setScale(Tuple2D)
-
transform
public void transform(Tuple2D<?> tuple)
Multiply this matrix by the tuple t and place the result back into the tuple (t = this*t).- Parameters:
tuple
- the tuple to be multiplied by this matrix and then replaced
-
transform
public void transform(Tuple2D<?> tuple, Tuple2D<?> result)
Multiply this matrix by the tuple t and and place the result into the tuple "result".This function is equivalent to:
result = this * [ t.x ] [ t.y ] [ 1 ]
- Parameters:
tuple
- the tuple to be multiplied by this matrixresult
- the tuple into which the product is placed
-
createInverse
@Pure public Transform2D createInverse()
Returns anTransform2D
object representing the inverse transformation. The inverse transform Tx' of this transform Tx maps coordinates transformed by Tx back to their original coordinates. In other words, Tx'(Tx(p)) = p = Tx(Tx'(p)).If this transform maps all coordinates onto a point or a line then it will not have an inverse, since coordinates that do not lie on the destination point or line will not have an inverse mapping. The
determinant
method can be used to determine if this transform has no inverse, in which case an exception will be thrown if thecreateInverse
method is called.- Returns:
- a new
Transform2D
object representing the inverse transformation. - See Also:
Matrix3d.determinant()
-
set
public void set(double m00, double m01, double m02, double m10, double m11, double m12)
Set the components of the transformation.- Parameters:
m00
- the [0][0] elementm01
- the [0][1] elementm02
- the [0][2] elementm10
- the [1][0] elementm11
- the [1][1] elementm12
- the [1][2] element
-
invert
public void invert()
Invert this transformation. The inverse transform Tx' of this transform Tx maps coordinates transformed by Tx back to their original coordinates. In other words, Tx'(Tx(p)) = p = Tx(Tx'(p)).If this transform maps all coordinates onto a point or a line then it will not have an inverse, since coordinates that do not lie on the destination point or line will not have an inverse mapping. The
determinant
method can be used to determine if this transform has no inverse, in which case an exception will be thrown if thecreateInverse
method is called.- Overrides:
invert
in classMatrix3d
- See Also:
Matrix3d.determinant()
-
invert
public void invert(Matrix3d matrix)
Invert this transformation. The inverse transform Tx' of this transform Tx maps coordinates transformed by Tx back to their original coordinates. In other words, Tx'(Tx(p)) = p = Tx(Tx'(p)).If this transform maps all coordinates onto a point or a line then it will not have an inverse, since coordinates that do not lie on the destination point or line will not have an inverse mapping. The
determinant
method can be used to determine if this transform has no inverse, in which case an exception will be thrown if thecreateInverse
method is called.- Overrides:
invert
in classMatrix3d
- Parameters:
matrix
- is the matrix to invert- See Also:
Matrix3d.determinant()
-
-