AffineTransformation class

Represents an affine transformation on the 2D Cartesian plane. It can be used to transform a {@link Coordinate} or {@link Geometry}. An affine transformation is a mapping of the 2D plane into itself via a series of transformations of the following basic types:

  • reflection (through a line)
  • rotation (around the origin)
  • scaling (relative to the origin)
  • shearing (in both the X and Y directions)
  • translation
In general, affine transformations preserve straightness and parallel lines, but do not preserve distance or shape.

An affine transformation can be represented by a 3x3 matrix in the following form:

T = | m00 m01 m02 |
    | m10 m11 m12 |
    |  0   0   1  |
A coordinate P = (x, y) can be transformed to a new coordinate P' = (x', y') by representing it as a 3x1 matrix and using matrix multiplication to compute:
| x' |  = T x | x |
| y' |        | y |
| 1  |        | 1 |

Transformation Composition

Affine transformations can be composed using the {@link #compose} method. Composition is computed via multiplication of the transformation matrices, and is defined as:
A.compose(B) = TB x TA
This produces a transformation whose effect is that of A followed by B. The methods {@link #reflect}, {@link #rotate}, {@link #scale}, {@link #shear}, and {@link #translate} have the effect of composing a transformation of that type with the transformation they are invoked on.

The composition of transformations is in general not commutative.

Transformation Inversion

Affine transformations may be invertible or non-invertible. If a transformation is invertible, then there exists an inverse transformation which when composed produces the identity transformation. The {@link #getInverse} method computes the inverse of a transformation, if one exists.

@author Martin Davis

Implemented types

Constructors

AffineTransformation()
Constructs a new identity transformation
AffineTransformation.fromCoordinates(Coordinate src0, Coordinate src1, Coordinate src2, Coordinate dest0, Coordinate dest1, Coordinate dest2)
Constructs a transformation which maps the given source points into the given destination points.
AffineTransformation.fromMatrix(List<double> matrix)
Constructs a new transformation whose matrix has the specified values.
AffineTransformation.fromMatrixValues(double m00, double m01, double m02, double m10, double m11, double m12)
Constructs a new transformation whose matrix has the specified values.
AffineTransformation.fromTransformation(AffineTransformation trans)
Constructs a transformation which is a copy of the given one.

Properties

hashCode int
The hash code for this object.
no setterinherited
m00 double
getter/setter pair
m01 double
getter/setter pair
m02 double
getter/setter pair
m10 double
getter/setter pair
m11 double
getter/setter pair
m12 double
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

compose(AffineTransformation trans) AffineTransformation
Updates this transformation to be the composition of this transformation with the given {@link AffineTransformation}. This produces a transformation whose effect is equal to applying this transformation followed by the argument transformation. mathematically,
composeBefore(AffineTransformation trans) AffineTransformation
Updates this transformation to be the composition of a given {@link AffineTransformation} with this transformation. This produces a transformation whose effect is equal to applying the argument transformation followed by this transformation. mathematically,
equals(Object? obj) bool
Tests if an object is an AffineTransformation and has the same matrix as this transformation.
filter(CoordinateSequence seq, int i) → void
Transforms the i'th coordinate in the input sequence
override
getDeterminant() double
Computes the determinant of the transformation matrix. The determinant is computed as:
getInverse() AffineTransformation
Computes the inverse of this transformation, if one exists. The inverse is the transformation which when composed with this one produces the identity transformation. A transformation has an inverse if and only if it is not singular (i.e. its determinant is non-zero). Geometrically, an transformation is non-invertible if it maps the plane to a line or a point. If no inverse exists this method will throw a NoninvertibleTransformationException.
getMatrixEntries() List<double>
Gets an array containing the entries of the transformation matrix. Only the 6 non-trivial entries are returned, in the sequence:
isDone() bool
Reports that this filter should continue to be executed until all coordinates have been transformed.
override
isGeometryChanged() bool
Reports whether the execution of this filter has modified the coordinates of the geometry. If so, {@link Geometry#geometryChanged} will be executed after this filter has finished being executed.
override
isIdentity() bool
Tests if this transformation is the identity transformation.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
reflect(double x0, double y0, double x1, double y1) AffineTransformation
Updates the value of this transformation to that of a reflection transformation composed with the current value.
reflectXY(double x, double y) AffineTransformation
Updates the value of this transformation to that of a reflection transformation composed with the current value.
rotate(double theta) AffineTransformation
Updates the value of this transformation to that of a rotation transformation composed with the current value. Positive angles correspond to a rotation in the counter-clockwise direction.
rotateSinCos(double sinTheta, double cosTheta) AffineTransformation
Updates the value of this transformation to that of a rotation around the origin composed with the current value, with the sin and cos of the rotation angle specified directly.
rotateSinCosXY(double sinTheta, double cosTheta, double x, double y) AffineTransformation
Updates the value of this transformation to that of a rotation around a given point composed with the current value, with the sin and cos of the rotation angle specified directly.
rotateTXY(double theta, double x, double y) AffineTransformation
Updates the value of this transformation to that of a rotation around a given point composed with the current value. Positive angles correspond to a rotation in the counter-clockwise direction.
scale(double xScale, double yScale) AffineTransformation
Updates the value of this transformation to that of a scale transformation composed with the current value.
setToIdentity() AffineTransformation
Sets this transformation to be the identity transformation. The identity transformation has the matrix:
setToReflection(double x0, double y0, double x1, double y1) AffineTransformation
Sets this transformation to be a reflection about the line defined by a line (x0,y0) - (x1,y1).
setToReflectionBasic(double x0, double y0, double x1, double y1) AffineTransformation
Explicitly computes the math for a reflection. May not work. @param x0 the X ordinate of one point on the reflection line @param y0 the Y ordinate of one point on the reflection line @param x1 the X ordinate of another point on the reflection line @param y1 the Y ordinate of another point on the reflection line @return this transformation, with an updated matrix
setToReflectionXY(double x, double y) AffineTransformation
Sets this transformation to be a reflection about the line defined by vector (x,y). The transformation for a reflection is computed by:
setToRotation(double theta) AffineTransformation
Sets this transformation to be a rotation around the origin. A positive rotation angle corresponds to a counter-clockwise rotation. The transformation matrix for a rotation by an angle theta has the value:
setToRotationSinCos(double sinTheta, double cosTheta) AffineTransformation
Sets this transformation to be a rotation around the origin by specifying the sin and cos of the rotation angle directly. The transformation matrix for the rotation has the value:
setToRotationSinCosXY(double sinTheta, double cosTheta, double x, double y) AffineTransformation
Sets this transformation to be a rotation around a given point (x,y) by specifying the sin and cos of the rotation angle directly. The transformation matrix for the rotation has the value:
setToRotationTXY(double theta, double x, double y) AffineTransformation
Sets this transformation to be a rotation around a given point (x,y). A positive rotation angle corresponds to a counter-clockwise rotation. The transformation matrix for a rotation by an angle theta has the value:
setToScale(double xScale, double yScale) AffineTransformation
Sets this transformation to be a scaling. The transformation matrix for a scale has the value:
setToShear(double xShear, double yShear) AffineTransformation
Sets this transformation to be a shear. The transformation matrix for a shear has the value:
setToTranslation(double dx, double dy) AffineTransformation
Sets this transformation to be a translation. For a translation by the vector (x, y) the transformation matrix has the value:
setTransformation(double m00, double m01, double m02, double m10, double m11, double m12) AffineTransformation
Sets this transformation's matrix to have the given values.
setTransformationFromTransformation(AffineTransformation trans) AffineTransformation
Sets this transformation to be a copy of the given one
shear(double xShear, double yShear) AffineTransformation
Updates the value of this transformation to that of a shear transformation composed with the current value.
toString() String
Gets a text representation of this transformation. The string is of the form:
override
transform(Coordinate src, Coordinate dest) Coordinate
Applies this transformation to the src coordinate and places the results in the dest coordinate (which may be the same as the source).
transformCS(CoordinateSequence seq, int i) → void
Applies this transformation to the i'th coordinate in the given CoordinateSequence.
transformGeom(Geometry g) Geometry
Creates a new {@link Geometry} which is the result of this transformation applied to the input Geometry.
translate(double x, double y) AffineTransformation
Updates the value of this transformation to that of a translation transformation composed with the current value.

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

reflectionInstance(double x0, double y0, double x1, double y1) AffineTransformation
Creates a transformation for a reflection about the line (x0,y0) - (x1,y1).
reflectionInstanceXY(double x, double y) AffineTransformation
Creates a transformation for a reflection about the line (0,0) - (x,y).
rotationInstance(double theta) AffineTransformation
Creates a transformation for a rotation about the origin by an angle theta. Positive angles correspond to a rotation in the counter-clockwise direction.
rotationInstanceSinCos(double sinTheta, double cosTheta) AffineTransformation
Creates a transformation for a rotation by an angle theta, specified by the sine and cosine of the angle. This allows providing exact values for sin(theta) and cos(theta) for the common case of rotations of multiples of quarter-circles.
rotationInstanceSinCosXY(double sinTheta, double cosTheta, double x, double y) AffineTransformation
Creates a transformation for a rotation about the point (x,y) by an angle theta, specified by the sine and cosine of the angle. This allows providing exact values for sin(theta) and cos(theta) for the common case of rotations of multiples of quarter-circles.
rotationInstanceTXY(double theta, double x, double y) AffineTransformation
Creates a transformation for a rotation about the point (x,y) by an angle theta. Positive angles correspond to a rotation in the counter-clockwise direction.
scaleInstance(double xScale, double yScale) AffineTransformation
Creates a transformation for a scaling relative to the origin.
scaleInstanceScaleXY(double xScale, double yScale, double x, double y) AffineTransformation
Creates a transformation for a scaling relative to the point (x,y).
shearInstance(double xShear, double yShear) AffineTransformation
Creates a transformation for a shear.
translationInstance(double x, double y) AffineTransformation
Creates a transformation for a translation.