math.geom2d
Class AffineTransform2D
- java.lang.Object
-
- math.geom2d.AffineTransform2D
-
- All Implemented Interfaces:
- java.lang.Cloneable, GeometricObject2D, Bijection2D, Transform2D
public class AffineTransform2D extends java.lang.Object implements Bijection2D, GeometricObject2D, java.lang.Cloneable
Base class for generic affine transforms in the plane. They include rotations, translations, shears, similarities, and combinations of these. Such transformations can be constructed by using coefficients specification, or by creating specialized instances, by using static methods.
-
-
Constructor Summary
Constructors Constructor and Description AffineTransform2D()Creates a new AffineTransform2D, initialized with Identity.AffineTransform2D(java.awt.geom.AffineTransform transform)Creates a new transform from a java AWT transform.AffineTransform2D(AffineTransform2D trans)Deprecated.not necessary to clone immutable objects (0.11.2)AffineTransform2D(double[] coefs)Creates a new Affine Transform by directly specifying the coefficients, in the order m00, m01, m02, m10, m11, m12 (different order of java.awt.geom.AffineTransform).AffineTransform2D(double xx, double yx, double tx, double xy, double yy, double ty)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method and Description double[][]affineMatrix()Returns the 3x3 square matrix representing the transform.booleanalmostEquals(GeometricObject2D obj, double eps)Checks if the two objects are similar up to a given threshold value.java.awt.geom.AffineTransformasAwtTransform()Returns this transform as an instance of java AWT AffineTransform.AffineTransform2Dchain(AffineTransform2D that)Returns the affine transform created by applying first this affine transform, then the affine transform given bythat.AffineTransform2Dclone()Deprecated.immutable objects do not need to be cloned (0.11.2)double[]coefficients()Returns coefficients of the transform in a linear array of 6 double.AffineTransform2Dconcatenate(AffineTransform2D that)Returns the affine transform created by applying first the affine transform given bythat, then this affine transform.static AffineTransform2Dcreate(AffineTransform2D trans)Creates a new affine transform by copying coefficients.static AffineTransform2Dcreate(double[] coefs)Creates an affine transform defined by an array of coefficients.static AffineTransform2Dcreate(double xx, double yx, double tx, double xy, double yy, double ty)static AffineTransform2DcreateGlideReflection(LinearShape2D line, double distance)Create a glide reflection, composed of a reflection by the given line, and a translation in the direction of the line by a distance given by second parameter.static AffineTransform2DcreateHomothecy(Point2D center, double k)Deprecated.replaced by scaling (0.11.1)static AffineTransform2DcreateIdentity()static AffineTransform2DcreateLineReflection(LinearShape2D line)Creates a reflection by the given line.static AffineTransform2DcreatePointReflection(Point2D center)Returns a center reflection around a point.static AffineTransform2DcreateQuadrantRotation(double x0, double y0, int numQuadrant)Creates a rotation composed of the given number of rotations by 90 degrees around the point given by (x0,y0).static AffineTransform2DcreateQuadrantRotation(int numQuadrant)Creates a rotation composed of the given number of rotations by 90 degrees around the origin.static AffineTransform2DcreateQuadrantRotation(Point2D center, int numQuadrant)Creates a rotation composed of the given number of rotations by 90 degrees around the given point.static AffineTransform2DcreateRotation(double angle)Creates a rotation around the origin, with angle in radians.static AffineTransform2DcreateRotation(double cx, double cy, double angle)Creates a rotation around the specified point, with angle in radians.static AffineTransform2DcreateRotation(Point2D center, double angle)Creates a rotation around the specified point, with angle in radians.static AffineTransform2DcreateScaling(double sx, double sy)Creates a scaling by the given coefficients, centered on the origin.static AffineTransform2DcreateScaling(Point2D center, double sx, double sy)Creates a scaling by the given coefficients, centered on the point given by (x0,y0).static AffineTransform2DcreateShear(double shx, double shy)Creates a Shear transform, using the classical Java notation.static AffineTransform2DcreateTransform(java.awt.geom.AffineTransform transform)Creates a new transform from a java AWT transform.static AffineTransform2DcreateTranslation(double dx, double dy)Return a translation by the given vector.static AffineTransform2DcreateTranslation(Vector2D vect)Return a translation by the given vector.booleanequals(java.lang.Object obj)AffineTransform2Dinvert()Returns the inverse transform.booleanisDirect()Tests if this affine transform is direct, i.e.static booleanisDirect(AffineTransform2D trans)Checks if the transform is direct, i.e.booleanisIdentity()Tests is this affine transform is equal to the identity transform.static booleanisIdentity(AffineTransform2D trans)Checks if the given transform is the identity transform.booleanisIsometry()Tests if this affine transform is an isometry, i.e.static booleanisIsometry(AffineTransform2D trans)Checks if the transform is an isometry, i.e.booleanisMotion()Tests if this affine transform is a motion, i.e.static booleanisMotion(AffineTransform2D trans)Checks if the transform is a motion, i.e.booleanisSimilarity()Tests if this affine transform is a similarity.static booleanisSimilarity(AffineTransform2D trans)Checks if the transform is an similarity, i.e.AffineTransform2DpreConcatenate(AffineTransform2D that)Return the affine transform created by applying first this affine transform, then the affine transform given bythat.java.lang.StringtoString()Displays the coefficients of the transform, row by row.Point2Dtransform(Point2D p)Computes the coordinates of the transformed point.Point2D[]transform(Point2D[] src, Point2D[] dst)Transforms an array of points, and returns the transformed points.
-
-
-
Constructor Detail
-
AffineTransform2D
public AffineTransform2D()
Creates a new AffineTransform2D, initialized with Identity.
-
AffineTransform2D
@Deprecated public AffineTransform2D(AffineTransform2D trans)
Deprecated. not necessary to clone immutable objects (0.11.2)Constructor by copy of an existing transform
-
AffineTransform2D
public AffineTransform2D(java.awt.geom.AffineTransform transform)
Creates a new transform from a java AWT transform.
-
AffineTransform2D
public AffineTransform2D(double[] coefs)
Creates a new Affine Transform by directly specifying the coefficients, in the order m00, m01, m02, m10, m11, m12 (different order of java.awt.geom.AffineTransform).
-
AffineTransform2D
public AffineTransform2D(double xx, double yx, double tx, double xy, double yy, double ty)
-
-
Method Detail
-
createIdentity
public static AffineTransform2D createIdentity()
- Since:
- 0.8.1
-
create
public static AffineTransform2D create(AffineTransform2D trans)
Creates a new affine transform by copying coefficients.- Since:
- 0.8.1
-
create
public static AffineTransform2D create(double[] coefs)
Creates an affine transform defined by an array of coefficients. The input array must have either 4 or 6 coefficients.- Since:
- 0.8.1
-
create
public static AffineTransform2D create(double xx, double yx, double tx, double xy, double yy, double ty)
- Since:
- 0.8.1
-
createGlideReflection
public static AffineTransform2D createGlideReflection(LinearShape2D line, double distance)
Create a glide reflection, composed of a reflection by the given line, and a translation in the direction of the line by a distance given by second parameter.
-
createHomothecy
@Deprecated public static AffineTransform2D createHomothecy(Point2D center, double k)
Deprecated. replaced by scaling (0.11.1)
-
createLineReflection
public static AffineTransform2D createLineReflection(LinearShape2D line)
Creates a reflection by the given line. The resulting transform is indirect.
-
createPointReflection
public static AffineTransform2D createPointReflection(Point2D center)
Returns a center reflection around a point. The resulting transform is equivalent to a rotation by 180 around this point.- Parameters:
center- the center of the reflection- Returns:
- an instance of AffineTransform2D representing a point reflection
-
createQuadrantRotation
public static AffineTransform2D createQuadrantRotation(int numQuadrant)
Creates a rotation composed of the given number of rotations by 90 degrees around the origin.
-
createQuadrantRotation
public static AffineTransform2D createQuadrantRotation(Point2D center, int numQuadrant)
Creates a rotation composed of the given number of rotations by 90 degrees around the given point.
-
createQuadrantRotation
public static AffineTransform2D createQuadrantRotation(double x0, double y0, int numQuadrant)
Creates a rotation composed of the given number of rotations by 90 degrees around the point given by (x0,y0).
-
createRotation
public static AffineTransform2D createRotation(double angle)
Creates a rotation around the origin, with angle in radians.
-
createRotation
public static AffineTransform2D createRotation(Point2D center, double angle)
Creates a rotation around the specified point, with angle in radians.
-
createRotation
public static AffineTransform2D createRotation(double cx, double cy, double angle)
Creates a rotation around the specified point, with angle in radians. If the angular distance of the angle with a multiple of PI/2 is lower than the threshold Shape2D.ACCURACY, the method assumes equality.
-
createScaling
public static AffineTransform2D createScaling(double sx, double sy)
Creates a scaling by the given coefficients, centered on the origin.
-
createScaling
public static AffineTransform2D createScaling(Point2D center, double sx, double sy)
Creates a scaling by the given coefficients, centered on the point given by (x0,y0).
-
createShear
public static AffineTransform2D createShear(double shx, double shy)
Creates a Shear transform, using the classical Java notation.- Parameters:
shx- shear in x-axisshy- shear in y-axis- Returns:
- a shear transform
-
createTransform
public static AffineTransform2D createTransform(java.awt.geom.AffineTransform transform)
Creates a new transform from a java AWT transform.
-
createTranslation
public static AffineTransform2D createTranslation(Vector2D vect)
Return a translation by the given vector.
-
createTranslation
public static AffineTransform2D createTranslation(double dx, double dy)
Return a translation by the given vector.
-
isIdentity
public static boolean isIdentity(AffineTransform2D trans)
Checks if the given transform is the identity transform.
-
isDirect
public static boolean isDirect(AffineTransform2D trans)
Checks if the transform is direct, i.e. it preserves the orientation of transformed shapes.- Returns:
- true if transform is direct.
-
isIsometry
public static boolean isIsometry(AffineTransform2D trans)
Checks if the transform is an isometry, i.e. a compound of translation, rotation and reflection. Isometry keeps area of shapes unchanged, but can change orientation (direct or indirect).- Returns:
- true in case of isometry.
-
isMotion
public static boolean isMotion(AffineTransform2D trans)
Checks if the transform is a motion, i.e. a compound of translations and rotations. Motions are special case of isometries that keep orientation (directed or undirected) of shapes unchanged.- Returns:
- true in case of motion.
-
isSimilarity
public static boolean isSimilarity(AffineTransform2D trans)
Checks if the transform is an similarity, i.e. transformation which keeps unchanged the global shape, up to a scaling factor.- Returns:
- true in case of similarity.
-
coefficients
public double[] coefficients()
Returns coefficients of the transform in a linear array of 6 double.
-
affineMatrix
public double[][] affineMatrix()
Returns the 3x3 square matrix representing the transform.- Returns:
- the 3x3 affine transform representing the matrix
-
asAwtTransform
public java.awt.geom.AffineTransform asAwtTransform()
Returns this transform as an instance of java AWT AffineTransform.
-
concatenate
public AffineTransform2D concatenate(AffineTransform2D that)
Returns the affine transform created by applying first the affine transform given bythat, then this affine transform. This is the equivalent method of the 'concatenate' method in java.awt.geom.AffineTransform.- Parameters:
that- the transform to apply first- Returns:
- the composition this * that
- Since:
- 0.6.3
-
chain
public AffineTransform2D chain(AffineTransform2D that)
Returns the affine transform created by applying first this affine transform, then the affine transform given bythat. This the equivalent method of the 'preConcatenate' method in java.awt.geom.AffineTransform.is equivalent to the sequence:shape = shape.transform(T1.chain(T2).chain(T3));
shape = shape.transform(T1); shape = shape.transform(T2); shape = shape.transform(T3);
- Parameters:
that- the transform to apply in a second step- Returns:
- the composition that * this
- Since:
- 0.6.3
-
preConcatenate
public AffineTransform2D preConcatenate(AffineTransform2D that)
Return the affine transform created by applying first this affine transform, then the affine transform given bythat. This the equivalent method of the 'preConcatenate' method in java.awt.geom.AffineTransform.- Parameters:
that- the transform to apply in a second step- Returns:
- the composition that * this
- Since:
- 0.6.3
-
isSimilarity
public boolean isSimilarity()
Tests if this affine transform is a similarity.
-
isMotion
public boolean isMotion()
Tests if this affine transform is a motion, i.e. is composed only of rotations and translations.
-
isIsometry
public boolean isIsometry()
Tests if this affine transform is an isometry, i.e. is equivalent to a compound of translations, rotations and reflections. Isometry keeps area of shapes unchanged, but can change orientation (direct or indirect).- Returns:
- true in case of isometry.
-
isDirect
public boolean isDirect()
Tests if this affine transform is direct, i.e. the sign of the determinant of the associated matrix is positive. Direct transforms preserve the orientation of transformed shapes.
-
isIdentity
public boolean isIdentity()
Tests is this affine transform is equal to the identity transform.- Returns:
- true if this transform is the identity transform
-
invert
public AffineTransform2D invert()
Returns the inverse transform. If the transform is not invertible, throws a new NonInvertibleTransform2DException.- Specified by:
invertin interfaceBijection2D- Since:
- 0.6.3
-
transform
public Point2D transform(Point2D p)
Computes the coordinates of the transformed point.- Specified by:
transformin interfaceTransform2D
-
transform
public Point2D[] transform(Point2D[] src, Point2D[] dst)
Description copied from interface:Transform2DTransforms an array of points, and returns the transformed points.- Specified by:
transformin interfaceTransform2D
-
almostEquals
public boolean almostEquals(GeometricObject2D obj, double eps)
Description copied from interface:GeometricObject2DChecks if the two objects are similar up to a given threshold value. This method can be used to compare the results of geometric computations, that introduce errors due to numerical computations.- Specified by:
almostEqualsin interfaceGeometricObject2D- Parameters:
obj- the object to compareeps- a threshold value, for example the minimal coordinate difference- Returns:
- true if both object have the same value up to the threshold
-
toString
public java.lang.String toString()
Displays the coefficients of the transform, row by row.- Overrides:
toStringin classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
clone
@Deprecated public AffineTransform2D clone()
Deprecated. immutable objects do not need to be cloned (0.11.2)- Overrides:
clonein classjava.lang.Object
-
-
DMelt 3.0 © DataMelt by jWork.ORG