AffineTransform class represents a 2D affine transform
that performs a linear mapping from 2D coordinates to other 2D
coordinates that preserves the "straightness" and
"parallelness" of lines. Affine transformations can be constructed
using sequences of translations, scales, flips, rotations, and shears.
Such a coordinate transformation can be represented by a 3 row by
3 column matrix with an implied last row of [ 0 0 1 ]. This matrix
transforms source coordinates (x,y) into
destination coordinates (x',y') by considering
them to be a column vector and multiplying the coordinate vector
by the matrix according to the following process:
[ x'] [ m00 m01 m02 ] [ x ] [ m00x + m01y + m02 ]
[ y'] = [ m10 m11 m12 ] [ y ] = [ m10x + m11y + m12 ]
[ 1 ] [ 0 0 1 ] [ 1 ] [ 1 ]
In some variations of the rotate methods in the
AffineTransform class, a double-precision argument
specifies the angle of rotation in radians.
These methods have special handling for rotations of approximately
90 degrees (including multiples such as 180, 270, and 360 degrees),
so that the common case of quadrant rotation is handled more
efficiently.
This special handling can cause angles very close to multiples of
90 degrees to be treated as if they were exact multiples of
90 degrees.
For small multiples of 90 degrees the range of angles treated
as a quadrant rotation is approximately 0.00000121 degrees wide.
This section explains why such special care is needed and how
it is implemented.
Since 90 degrees is represented as PI/2 in radians,
and since PI is a transcendental (and therefore irrational) number,
it is not possible to exactly represent a multiple of 90 degrees as
an exact double precision value measured in radians.
As a result it is theoretically impossible to describe quadrant
rotations (90, 180, 270 or 360 degrees) using these values.
Double precision floating point values can get very close to
non-zero multiples of PI/2 but never close enough
for the sine or cosine to be exactly 0.0, 1.0 or -1.0.
The implementations of Math.sin() and
Math.cos() correspondingly never return 0.0
for any case other than Math.sin(0.0).
These same implementations do, however, return exactly 1.0 and
-1.0 for some range of numbers around each multiple of 90
degrees since the correct answer is so close to 1.0 or -1.0 that
the double precision significand cannot represent the difference
as accurately as it can for numbers that are near 0.0.
The net result of these issues is that if the
Math.sin() and Math.cos() methods
are used to directly generate the values for the matrix modifications
during these radian-based rotation operations then the resulting
transform is never strictly classifiable as a quadrant rotation
even for a simple case like rotate(Math.PI/2.0),
due to minor variations in the matrix caused by the non-0.0 values
obtained for the sine and cosine.
If these transforms are not classified as quadrant rotations then
subsequent code which attempts to optimize further operations based
upon the type of the transform will be relegated to its most general
implementation.
Because quadrant rotations are fairly common,
this class should handle these cases reasonably quickly, both in
applying the rotations to the transform and in applying the resulting
transform to the coordinates.
To facilitate this optimal handling, the methods which take an angle
of rotation measured in radians attempt to detect angles that are
intended to be quadrant rotations and treat them as such.
These methods therefore treat an angle theta as a quadrant
rotation if either Math.sin(theta) or
Math.cos(theta) returns exactly 1.0 or -1.0.
As a rule of thumb, this property holds true for a range of
approximately 0.0000000211 radians (or 0.00000121 degrees) around
small multiples of Math.PI/2.0.
| Modifier and Type | Field and Description |
|---|---|
| pack-priv static final int | APPLY_IDENTITY
This constant is used for the internal state variable to indicate that no calculations need to be performed and that the source coordinates only need to be copied to their destinations to complete the transformation equation of this transform. |
| pack-priv static final int | APPLY_SCALE
This constant is used for the internal state variable to indicate that the scaling components of the matrix (m00 and m11) need to be factored in to complete the transformation equation of this transform. |
| pack-priv static final int | APPLY_SHEAR
This constant is used for the internal state variable to indicate that the shearing components of the matrix (m01 and m10) need to be factored in to complete the transformation equation of this transform. |
| pack-priv static final int | APPLY_TRANSLATE
This constant is used for the internal state variable to indicate that the translation components of the matrix (m02 and m12) need to be added to complete the transformation equation of this transform. |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| pack-priv double | m00
The X coordinate scaling element of the 3x3 affine transformation matrix. |
| pack-priv double | m01
The X coordinate shearing element of the 3x3 affine transformation matrix. |
| pack-priv double | m02
The X coordinate of the translation element of the 3x3 affine transformation matrix. |
| pack-priv double | m10
The Y coordinate shearing element of the 3x3 affine transformation matrix. |
| pack-priv double | m11
The Y coordinate scaling element of the 3x3 affine transformation matrix. |
| pack-priv double | m12
The Y coordinate of the translation element of the 3x3 affine transformation matrix. |
| private static final int[] | |
| private static final long | serialVersionUID
Use serialVersionUID from JDK 1.2 for interoperability. |
| pack-priv transient int | state
This field keeps track of which components of the matrix need to be applied when performing a transformation. |
| private transient int | type
This field caches the current transformation type of the matrix. |
| public static final int | TYPE_FLIP
This flag bit indicates that the transform defined by this object performs a mirror image flip about some axis which changes the normally right handed coordinate system into a left handed system in addition to the conversions indicated by other flag bits. |
| public static final int | TYPE_GENERAL_ROTATION
This flag bit indicates that the transform defined by this object performs a rotation by an arbitrary angle in addition to the conversions indicated by other flag bits. |
| public static final int | TYPE_GENERAL_SCALE
This flag bit indicates that the transform defined by this object performs a general scale in addition to the conversions indicated by other flag bits. |
| public static final int | TYPE_GENERAL_TRANSFORM
This constant indicates that the transform defined by this object performs an arbitrary conversion of the input coordinates. |
| public static final int | TYPE_IDENTITY
This constant indicates that the transform defined by this object is an identity transform. |
| public static final int | TYPE_MASK_ROTATION
This constant is a bit mask for any of the rotation flag bits. |
| public static final int | TYPE_MASK_SCALE
This constant is a bit mask for any of the scale flag bits. |
| public static final int | TYPE_QUADRANT_ROTATION
This flag bit indicates that the transform defined by this object performs a quadrant rotation by some multiple of 90 degrees in addition to the conversions indicated by other flag bits. |
| public static final int | TYPE_TRANSLATION
This flag bit indicates that the transform defined by this object performs a translation in addition to the conversions indicated by other flag bits. |
| public static final int | TYPE_UNIFORM_SCALE
This flag bit indicates that the transform defined by this object performs a uniform scale in addition to the conversions indicated by other flag bits. |
| private static final int |
| Access | Constructor and Description |
|---|---|
| private | |
| public | |
| public | AffineTransform(AffineTransform
the Tx)AffineTransform object to copyConstructs a new |
| public | AffineTransform(float
the X coordinate scaling element of the 3x3 matrix m00, float the Y coordinate shearing element of the 3x3 matrix m10, float the X coordinate shearing element of the 3x3 matrix m01, float the Y coordinate scaling element of the 3x3 matrix m11, float the X coordinate translation element of the 3x3 matrix m02, float the Y coordinate translation element of the 3x3 matrix m12)Constructs a new |
| public | AffineTransform(float[]
the float array containing the values to be set
in the new flatmatrix)AffineTransform object. The length of the
array is assumed to be at least 4. If the length of the array is
less than 6, only the first 4 values are taken. If the length of
the array is greater than 6, the first 6 values are taken.Constructs a new |
| public | AffineTransform(double
the X coordinate scaling element of the 3x3 matrix m00, double the Y coordinate shearing element of the 3x3 matrix m10, double the X coordinate shearing element of the 3x3 matrix m01, double the Y coordinate scaling element of the 3x3 matrix m11, double the X coordinate translation element of the 3x3 matrix m02, double the Y coordinate translation element of the 3x3 matrix m12)Constructs a new |
| public | AffineTransform(double[]
the double array containing the values to be set
in the new flatmatrix)AffineTransform object. The length of the
array is assumed to be at least 4. If the length of the array is
less than 6, only the first 4 values are taken. If the length of
the array is greater than 6, the first 6 values are taken.Constructs a new |
| Modifier and Type | Method and Description |
|---|---|
| private static double | |
| private void | calculateType()
This is the utility function to calculate the flag bits when they have not been cached. |
| public Object | Returns: anObject that is a copy of this
AffineTransform object.Overrides java. Returns a copy of this |
| public void | concatenate(AffineTransform
the Tx)AffineTransform object to be
concatenated with this AffineTransform object.Concatenates an |
| public AffineTransform | Returns: a newAffineTransform object representing the
inverse transformation.Returns an |
| public Shape | Returns: a newShape object that defines the geometry
of the transformed Shape, or null if pSrc is null.the specified pSrc)Shape object to be
transformed by this transform.Returns a new |
| public Point2D | Returns: ptDst, which contains the result of the
transformation.the distance vector to be delta transformed ptSrc, Point2D the resulting transformed distance vector ptDst)Transforms the relative distance vector specified by
|
| public void | deltaTransform(double[]
the array containing the source distance vectors.
Each vector is stored as a pair of relative x, y coordinates. srcPts, int the offset to the first vector to be transformed
in the source array srcOff, double[] the array into which the transformed distance vectors
are returned. Each vector is stored as a pair of relative
x, y coordinates. dstPts, int the offset to the location of the first
transformed vector that is stored in the destination array dstOff, int the number of vector coordinate pairs to be
transformed numPts)Transforms an array of relative distance vectors by this transform. |
| public boolean | Returns: true if obj equals this
AffineTransform object; false otherwise.the obj)Object to test for equality with this
AffineTransformOverrides java. Returns |
| private static boolean | equals(double a, double b)
Compares the given floating point values, with negative zero considered equals to positive zero. |
| public double | Returns: the determinant of the matrix used to transform the coordinates.Returns the determinant of the matrix representation of the transform. |
| public void | getMatrix(double[]
the double array used to store the returned
values. flatmatrix)Retrieves the 6 specifiable values in the 3x3 affine transformation matrix and places them into an array of double precisions values. |
| public static AffineTransform | Returns: anAffineTransform object that rotates
coordinates by the specified number of quadrants.the number of 90 degree arcs to rotate by numquadrants)Returns a transform that rotates coordinates by the specified number of quadrants. |
| public static AffineTransform | Returns: anAffineTransform object that rotates
coordinates by the specified number of quadrants around the
specified anchor point.the number of 90 degree arcs to rotate by numquadrants, double the X coordinate of the rotation anchor point anchorx, double the Y coordinate of the rotation anchor point anchory)Returns a transform that rotates coordinates by the specified number of quadrants around the specified anchor point. |
| public static AffineTransform | Returns: anAffineTransform object that is a rotation
transformation, created with the specified angle of rotation.the angle of rotation measured in radians theta)Returns a transform representing a rotation transformation. |
| public static AffineTransform | Returns: anAffineTransform object that rotates
coordinates around the specified point by the specified angle of
rotation.the angle of rotation measured in radians theta, double the X coordinate of the rotation anchor point anchorx, double the Y coordinate of the rotation anchor point anchory)Returns a transform that rotates coordinates around an anchor point. |
| public static AffineTransform | Returns: anAffineTransform object that rotates
coordinates according to the specified rotation vector.the X coordinate of the rotation vector vecx, double the Y coordinate of the rotation vector vecy)Returns a transform that rotates coordinates according to a rotation vector. |
| public static AffineTransform | Returns: anAffineTransform object that rotates
coordinates around the specified point according to the
specified rotation vector.the X coordinate of the rotation vector vecx, double the Y coordinate of the rotation vector vecy, double the X coordinate of the rotation anchor point anchorx, double the Y coordinate of the rotation anchor point anchory)Returns a transform that rotates coordinates around an anchor point according to a rotation vector. |
| public static AffineTransform | Returns: anAffineTransform object that scales
coordinates by the specified factors.the factor by which coordinates are scaled along the
X axis direction sx, double the factor by which coordinates are scaled along the
Y axis direction sy)Returns a transform representing a scaling transformation. |
| public double | Returns: a double value that ism00 element of the
3x3 affine transformation matrix.Returns the |
| public double | Returns: a double value that ism11 element of the
3x3 affine transformation matrix.Returns the |
| public static AffineTransform | Returns: anAffineTransform object that shears
coordinates by the specified multipliers.the multiplier by which coordinates are shifted in the
direction of the positive X axis as a factor of their Y coordinate shx, double the multiplier by which coordinates are shifted in the
direction of the positive Y axis as a factor of their X coordinate shy)Returns a transform representing a shearing transformation. |
| public double | Returns: a double value that is the X coordinate of the shearing element of the affine transformation matrix.Returns the X coordinate shearing element (m01) of the 3x3 affine transformation matrix. |
| public double | Returns: a double value that is the Y coordinate of the shearing element of the affine transformation matrix.Returns the Y coordinate shearing element (m10) of the 3x3 affine transformation matrix. |
| public static AffineTransform | Returns: anAffineTransform object that represents a
translation transformation, created with the specified vector.the distance by which coordinates are translated in the
X axis direction tx, double the distance by which coordinates are translated in the
Y axis direction ty)Returns a transform representing a translation transformation. |
| public double | Returns: a double value that is the X coordinate of the translation element of the affine transformation matrix.Returns the X coordinate of the translation element (m02) of the 3x3 affine transformation matrix. |
| public double | Returns: a double value that is the Y coordinate of the translation element of the affine transformation matrix.Returns the Y coordinate of the translation element (m12) of the 3x3 affine transformation matrix. |
| public int | Returns: the OR combination of any of the indicated flags that apply to this transformRetrieves the flag bits describing the conversion properties of this transform. |
| private static long | hash(double m)
Returns a hash code for the given value, with negative zero collapsed to the single positive zero. |
| public int | Returns: a hash code for this transform.Overrides java. Returns the hashcode for this transform. |
| public Point2D | Returns: ptDst, which contains the result of the
inverse transform.the point to be inverse transformed ptSrc, Point2D the resulting transformed point ptDst)Inverse transforms the specified |
| public void | inverseTransform(double[]
the array containing the source point coordinates.
Each point is stored as a pair of x, y coordinates. srcPts, int the offset to the first point to be transformed
in the source array srcOff, double[] the array into which the transformed point
coordinates are returned. Each point is stored as a pair of
x, y coordinates. dstPts, int the offset to the location of the first
transformed point that is stored in the destination array dstOff, int the number of point objects to be transformed numPts)Inverse transforms an array of double precision coordinates by this transform. |
| public void | |
| public boolean | Returns: true if this AffineTransform is
an identity transform; false otherwise.Returns |
| public void | preConcatenate(AffineTransform
the Tx)AffineTransform object to be
concatenated with this AffineTransform object.Concatenates an |
| public void | quadrantRotate(int
the number of 90 degree arcs to rotate by numquadrants)Concatenates this transform with a transform that rotates coordinates by the specified number of quadrants. |
| public void | quadrantRotate(int
the number of 90 degree arcs to rotate by numquadrants, double the X coordinate of the rotation anchor point anchorx, double the Y coordinate of the rotation anchor point anchory)Concatenates this transform with a transform that rotates coordinates by the specified number of quadrants around the specified anchor point. |
| private void | |
| public void | rotate(double
the angle of rotation measured in radians theta)Concatenates this transform with a rotation transformation. |
| public void | rotate(double
the angle of rotation measured in radians theta, double the X coordinate of the rotation anchor point anchorx, double the Y coordinate of the rotation anchor point anchory)Concatenates this transform with a transform that rotates coordinates around an anchor point. |
| public void | rotate(double
the X coordinate of the rotation vector vecx, double the Y coordinate of the rotation vector vecy)Concatenates this transform with a transform that rotates coordinates according to a rotation vector. |
| public void | rotate(double
the X coordinate of the rotation vector vecx, double the Y coordinate of the rotation vector vecy, double the X coordinate of the rotation anchor point anchorx, double the Y coordinate of the rotation anchor point anchory)Concatenates this transform with a transform that rotates coordinates around an anchor point according to a rotation vector. |
| private void | |
| private void | |
| private void | |
| public void | scale(double
the factor by which coordinates are scaled along the
X axis direction sx, double the factor by which coordinates are scaled along the
Y axis direction sy)Concatenates this transform with a scaling transformation. |
| public void | |
| public void | setToQuadrantRotation(int
the number of 90 degree arcs to rotate by numquadrants)Sets this transform to a rotation transformation that rotates coordinates by the specified number of quadrants. |
| public void | setToQuadrantRotation(int
the number of 90 degree arcs to rotate by numquadrants, double the X coordinate of the rotation anchor point anchorx, double the Y coordinate of the rotation anchor point anchory)Sets this transform to a translated rotation transformation that rotates coordinates by the specified number of quadrants around the specified anchor point. |
| public void | setToRotation(double
the angle of rotation measured in radians theta)Sets this transform to a rotation transformation. |
| public void | setToRotation(double
the angle of rotation measured in radians theta, double the X coordinate of the rotation anchor point anchorx, double the Y coordinate of the rotation anchor point anchory)Sets this transform to a translated rotation transformation. |
| public void | setToRotation(double
the X coordinate of the rotation vector vecx, double the Y coordinate of the rotation vector vecy)Sets this transform to a rotation transformation that rotates coordinates according to a rotation vector. |
| public void | setToRotation(double
the X coordinate of the rotation vector vecx, double the Y coordinate of the rotation vector vecy, double the X coordinate of the rotation anchor point anchorx, double the Y coordinate of the rotation anchor point anchory)Sets this transform to a rotation transformation that rotates coordinates around an anchor point according to a rotation vector. |
| public void | setToScale(double
the factor by which coordinates are scaled along the
X axis direction sx, double the factor by which coordinates are scaled along the
Y axis direction sy)Sets this transform to a scaling transformation. |
| public void | setToShear(double
the multiplier by which coordinates are shifted in the
direction of the positive X axis as a factor of their Y coordinate shx, double the multiplier by which coordinates are shifted in the
direction of the positive Y axis as a factor of their X coordinate shy)Sets this transform to a shearing transformation. |
| public void | setToTranslation(double
the distance by which coordinates are translated in the
X axis direction tx, double the distance by which coordinates are translated in the
Y axis direction ty)Sets this transform to a translation transformation. |
| public void | setTransform(AffineTransform
the Tx)AffineTransform object from which to
copy the transformSets this transform to a copy of the transform in the specified
|
| public void | setTransform(double
the X coordinate scaling element of the 3x3 matrix m00, double the Y coordinate shearing element of the 3x3 matrix m10, double the X coordinate shearing element of the 3x3 matrix m01, double the Y coordinate scaling element of the 3x3 matrix m11, double the X coordinate translation element of the 3x3 matrix m02, double the Y coordinate translation element of the 3x3 matrix m12)Sets this transform to the matrix specified by the 6 double precision values. |
| public void | shear(double
the multiplier by which coordinates are shifted in the
direction of the positive X axis as a factor of their Y coordinate shx, double the multiplier by which coordinates are shifted in the
direction of the positive Y axis as a factor of their X coordinate shy)Concatenates this transform with a shearing transformation. |
| private void | |
| public String | Returns: aString representing the value of this
Object.Overrides java. Returns a |
| public Point2D | |
| public void | transform(Point2D[]
the array containing the source point objects ptSrc, int the offset to the first point object to be
transformed in the source array srcOff, Point2D[] the array into which the transform point objects are
returned ptDst, int the offset to the location of the first
transformed point object that is stored in the destination array dstOff, int the number of point objects to be transformed numPts)Transforms an array of point objects by this transform. |
| public void | transform(float[]
the array containing the source point coordinates.
Each point is stored as a pair of x, y coordinates. srcPts, int the offset to the first point to be transformed
in the source array srcOff, float[] the array into which the transformed point coordinates
are returned. Each point is stored as a pair of x, y
coordinates. dstPts, int the offset to the location of the first
transformed point that is stored in the destination array dstOff, int the number of points to be transformed numPts)Transforms an array of floating point coordinates by this transform. |
| public void | transform(double[]
the array containing the source point coordinates.
Each point is stored as a pair of x, y coordinates. srcPts, int the offset to the first point to be transformed
in the source array srcOff, double[] the array into which the transformed point
coordinates are returned. Each point is stored as a pair of
x, y coordinates. dstPts, int the offset to the location of the first
transformed point that is stored in the destination array dstOff, int the number of point objects to be transformed numPts)Transforms an array of double precision coordinates by this transform. |
| public void | transform(float[]
the array containing the source point coordinates.
Each point is stored as a pair of x, y coordinates. srcPts, int the offset to the first point to be transformed
in the source array srcOff, double[] the array into which the transformed point coordinates
are returned. Each point is stored as a pair of x, y
coordinates. dstPts, int the offset to the location of the first
transformed point that is stored in the destination array dstOff, int the number of points to be transformed numPts)Transforms an array of floating point coordinates by this transform and stores the results into an array of doubles. |
| public void | transform(double[]
the array containing the source point coordinates.
Each point is stored as a pair of x, y coordinates. srcPts, int the offset to the first point to be transformed
in the source array srcOff, float[] the array into which the transformed point
coordinates are returned. Each point is stored as a pair of
x, y coordinates. dstPts, int the offset to the location of the first
transformed point that is stored in the destination array dstOff, int the number of point objects to be transformed numPts)Transforms an array of double precision coordinates by this transform and stores the results into an array of floats. |
| public void | translate(double
the distance by which coordinates are translated in the
X axis direction tx, double the distance by which coordinates are translated in the
Y axis direction ty)Concatenates this transform with a translation transformation. |
| pack-priv void | updateState()
Manually recalculates the state of the transform when the matrix changes too much to predict the effects on the state. |
| private void | writeObject(ObjectOutputStream
the s)ObjectOutputStream to writeWrites default serializable fields to stream. |