math.geom2d
Class AffineTransform2D

java.lang.Object
  extended by 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
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)
          Constructor by copy of an existing transform
AffineTransform2D(double[] coefs)
           
AffineTransform2D(double xx, double yx, double tx, double xy, double yy, double ty)
           
 
Method Summary
 double[][] affineMatrix()
          Returns the 3x3 square matrix representing the transform.
 boolean almostEquals(GeometricObject2D obj, double eps)
          Checks if the two objects are similar up to a given threshold value.
 java.awt.geom.AffineTransform asAwtTransform()
          Returns this transform as an instance of java AWT AffineTransform.
 AffineTransform2D chain(AffineTransform2D that)
          Returns the affine transform created by applying first this affine transform, then the affine transform given by that.
 AffineTransform2D clone()
           
 double[] coefficients()
          Returns coefficients of the transform in a linear array of 6 double.
 AffineTransform2D concatenate(AffineTransform2D that)
          Returns the affine transform created by applying first the affine transform given by that, then this affine transform.
static AffineTransform2D create(AffineTransform2D trans)
          Creates a new affine transform by copying coefficients.
static AffineTransform2D create(double[] coefs)
          Creates an affine transform defined by an array of coefficients.
static AffineTransform2D create(double xx, double yx, double tx, double xy, double yy, double ty)
           
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.
static AffineTransform2D createHomothecy(Point2D center, double k)
          Deprecated. replaced by scaling (0.11.1)
static AffineTransform2D createIdentity()
           
static AffineTransform2D createLineReflection(LinearShape2D line)
          Creates a reflection by the given line.
static AffineTransform2D createPointReflection(Point2D center)
          Returns a center reflection around a point.
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).
static AffineTransform2D createQuadrantRotation(int numQuadrant)
          Creates a rotation composed of the given number of rotations by 90 degrees around the origin.
static AffineTransform2D createQuadrantRotation(Point2D center, int numQuadrant)
          Creates a rotation composed of the given number of rotations by 90 degrees around the given point.
static AffineTransform2D createRotation(double angle)
          Creates a rotation around the origin, with angle in radians.
static AffineTransform2D createRotation(double cx, double cy, double angle)
          Creates a rotation around the specified point, with angle in radians.
static AffineTransform2D createRotation(Point2D center, double angle)
          Creates a rotation around the specified point, with angle in radians.
static AffineTransform2D createScaling(double sx, double sy)
          Creates a scaling by the given coefficients, centered on the origin.
static AffineTransform2D createScaling(Point2D center, double sx, double sy)
          Creates a scaling by the given coefficients, centered on the point given by (x0,y0).
static AffineTransform2D createShear(double shx, double shy)
          Creates a Shear transform, using the classical Java notation.
static AffineTransform2D createTransform(java.awt.geom.AffineTransform transform)
          Creates a new transform from a java AWT transform.
static AffineTransform2D createTranslation(double dx, double dy)
          Return a translation by the given vector.
static AffineTransform2D createTranslation(Vector2D vect)
          Return a translation by the given vector.
 boolean equals(java.lang.Object obj)
           
 AffineTransform2D invert()
          Returns the inverse transform.
 boolean isDirect()
          Tests if this affine transform is direct, i.e. the sign of the determinant of the associated matrix is positive.
static boolean isDirect(AffineTransform2D trans)
          Checks if the transform is direct, i.e. it preserves the orientation of transformed shapes.
 boolean isIdentity()
          Tests is this affine transform is equal to the identity transform.
static boolean isIdentity(AffineTransform2D trans)
          Checks if the given transform is the identity transform.
 boolean isIsometry()
          Tests if this affine transform is an isometry, i.e. is equivalent to a compound of translations, rotations and reflections.
static boolean isIsometry(AffineTransform2D trans)
          Checks if the transform is an isometry, i.e. a compound of translation, rotation and reflection.
 boolean isMotion()
          Tests if this affine transform is a motion, i.e. is composed only of rotations and translations.
static boolean isMotion(AffineTransform2D trans)
          Checks if the transform is a motion, i.e. a compound of translations and rotations.
 boolean isSimilarity()
          Tests if this affine transform is a similarity.
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.
 AffineTransform2D preConcatenate(AffineTransform2D that)
          Return the affine transform created by applying first this affine transform, then the affine transform given by that.
 java.lang.String toString()
          Displays the coefficients of the transform, row by row.
 Point2D transform(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.
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AffineTransform2D

public AffineTransform2D()
Creates a new AffineTransform2D, initialized with Identity.


AffineTransform2D

public AffineTransform2D(AffineTransform2D trans)
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)

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-axis
shy - 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 by that, 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 by that. This the equivalent method of the 'preConcatenate' method in java.awt.geom.AffineTransform.
 shape = shape.transform(T1.chain(T2).chain(T3));
 
is equivalent to the sequence:
 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 by that. 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:
invert in interface Bijection2D
Since:
0.6.3

transform

public Point2D transform(Point2D p)
Computes the coordinates of the transformed point.

Specified by:
transform in interface Transform2D

transform

public Point2D[] transform(Point2D[] src,
                           Point2D[] dst)
Description copied from interface: Transform2D
Transforms an array of points, and returns the transformed points.

Specified by:
transform in interface Transform2D

almostEquals

public boolean almostEquals(GeometricObject2D obj,
                            double eps)
Description copied from interface: GeometricObject2D
Checks 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:
almostEquals in interface GeometricObject2D
Parameters:
obj - the object to compare
eps - 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:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

clone

public AffineTransform2D clone()
Overrides:
clone in class java.lang.Object