public class AffineTransformation extends Objectimplements Cloneable , CoordinateSequenceFilter
Coordinate or
Geometry. An affine transformation is a mapping of the 2D plane into itself via a series of transformations of the following basic types:
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 |
compose(com.vividsolutions.jts.geom.util.AffineTransformation) method. Composition is computed via multiplication of the transformation matrices, and is defined as:
This produces a transformation whose effect is that of A followed by B. The methodsA.compose(B) = TB x TA
reflect(double, double, double, double),
rotate(double),
scale(double, double),
shear(double, double), and
translate(double, double) 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.
getInverse() method computes the inverse of a transformation, if one exists.
| Constructor and Description |
|---|
AffineTransformation()
Constructs a new identity transformation
|
AffineTransformation(AffineTransformation
Constructs a transformation which is a copy of the given one.
|
AffineTransformation(Coordinate
Constructs a transformation which maps the given source points into the given destination points.
|
AffineTransformation(double[] matrix)
Constructs a new transformation whose matrix has the specified values.
|
AffineTransformation(double m00, double m01, double m02, double m10, double m11, double m12)
Constructs a new transformation whose matrix has the specified values.
|
| Modifier and Type | Method and Description |
|---|---|
Object |
clone()
Clones this transformation
|
AffineTransformation |
compose(AffineTransformation
Updates this transformation to be the composition of this transformation with the given
AffineTransformation.
|
AffineTransformation |
composeBefore(AffineTransformation
Updates this transformation to be the composition of a given
AffineTransformation with this transformation.
|
boolean |
equals(Object
Tests if an object is an
AffineTransformation and has the same matrix as this transformation.
|
void |
filter(CoordinateSequence
Transforms the i'th coordinate in the input sequence
|
double |
getDeterminant()
Computes the determinant of the transformation matrix.
|
AffineTransformation |
getInverse()
Computes the inverse of this transformation, if one exists.
|
double[] |
getMatrixEntries()
Gets an array containing the entries of the transformation matrix.
|
boolean |
isDone()
Reports that this filter should continue to be executed until all coordinates have been transformed.
|
boolean |
isGeometryChanged()
Reports whether the execution of this filter has modified the coordinates of the geometry.
|
boolean |
isIdentity()
Tests if this transformation is the identity transformation.
|
AffineTransformation |
reflect(double x, double y)
Updates the value of this transformation to that of a reflection transformation composed with the current value.
|
AffineTransformation |
reflect(double x0, double y0, double x1, double y1)
Updates the value of this transformation to that of a reflection transformation composed with the current value.
|
static AffineTransformation |
reflectionInstance(double x, double y)
Creates a transformation for a reflection about the line (0,0) - (x,y).
|
static AffineTransformation |
reflectionInstance(double x0, double y0, double x1, double y1)
Creates a transformation for a reflection about the line (x0,y0) - (x1,y1).
|
AffineTransformation |
rotate(double theta)
Updates the value of this transformation to that of a rotation transformation composed with the current value.
|
AffineTransformation |
rotate(double sinTheta, double cosTheta)
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.
|
AffineTransformation |
rotate(double theta, double x, double y)
Updates the value of this transformation to that of a rotation around a given point composed with the current value.
|
AffineTransformation |
rotate(double sinTheta, double cosTheta, double x, double y)
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.
|
static AffineTransformation |
rotationInstance(double theta)
Creates a transformation for a rotation about the origin by an angle
theta.
|
static AffineTransformation |
rotationInstance(double sinTheta, double cosTheta)
Creates a transformation for a rotation by an angle
theta, specified by the sine and cosine of the angle.
|
static AffineTransformation |
rotationInstance(double theta, double x, double y)
Creates a transformation for a rotation about the point (x,y) by an angle
theta.
|
static AffineTransformation |
rotationInstance(double sinTheta, double cosTheta, double x, double y)
Creates a transformation for a rotation about the point (x,y) by an angle
theta, specified by the sine and cosine of the angle.
|
AffineTransformation |
scale(double xScale, double yScale)
Updates the value of this transformation to that of a scale transformation composed with the current value.
|
static AffineTransformation |
scaleInstance(double xScale, double yScale)
Creates a transformation for a scaling relative to the origin.
|
static AffineTransformation |
scaleInstance(double xScale, double yScale, double x, double y)
Creates a transformation for a scaling relative to the point (x,y).
|
AffineTransformation |
setToIdentity()
Sets this transformation to be the identity transformation.
|
AffineTransformation |
setToReflection(double x, double y)
Sets this transformation to be a reflection about the line defined by vector (x,y).
|
AffineTransformation |
setToReflection(double x0, double y0, double x1, double y1)
Sets this transformation to be a reflection about the line defined by a line
(x0,y0) - (x1,y1).
|
AffineTransformation |
setToReflectionBasic(double x0, double y0, double x1, double y1)
Explicitly computes the math for a reflection.
|
AffineTransformation |
setToRotation(double theta)
Sets this transformation to be a rotation around the origin.
|
AffineTransformation |
setToRotation(double sinTheta, double cosTheta)
Sets this transformation to be a rotation around the origin by specifying the sin and cos of the rotation angle directly.
|
AffineTransformation |
setToRotation(double theta, double x, double y)
Sets this transformation to be a rotation around a given point (x,y).
|
AffineTransformation |
setToRotation(double sinTheta, double cosTheta, double x, double y)
Sets this transformation to be a rotation around a given point (x,y) by specifying the sin and cos of the rotation angle directly.
|
AffineTransformation |
setToScale(double xScale, double yScale)
Sets this transformation to be a scaling.
|
AffineTransformation |
setToShear(double xShear, double yShear)
Sets this transformation to be a shear.
|
AffineTransformation |
setToTranslation(double dx, double dy)
Sets this transformation to be a translation.
|
AffineTransformation |
setTransformation(AffineTransformation
Sets this transformation to be a copy of the given one
|
AffineTransformation |
setTransformation(double m00, double m01, double m02, double m10, double m11, double m12)
Sets this transformation's matrix to have the given values.
|
AffineTransformation |
shear(double xShear, double yShear)
Updates the value of this transformation to that of a shear transformation composed with the current value.
|
static AffineTransformation |
shearInstance(double xShear, double yShear)
Creates a transformation for a shear.
|
String |
toString()
Gets a text representation of this transformation.
|
Coordinate |
transform(Coordinate
Applies this transformation to the
src coordinate and places the results in the
dest coordinate (which may be the same as the source).
|
void |
transform(CoordinateSequence
Applies this transformation to the i'th coordinate in the given CoordinateSequence.
|
Geometry |
transform(Geometry
Cretaes a new @link Geometry which is the result of this transformation applied to the input Geometry.
|
AffineTransformation |
translate(double x, double y)
Updates the value of this transformation to that of a translation transformation composed with the current value.
|
static AffineTransformation |
translationInstance(double x, double y)
Creates a transformation for a translation.
|
public AffineTransformation()
public AffineTransformation(double[] matrix)
matrix - an array containing the 6 values { m00, m01, m02, m10, m11, m12 }
NullPointerException - if matrix is null
ArrayIndexOutOfBoundsException - if matrix is too small
public AffineTransformation(double m00,
double m01,
double m02,
double m10,
double m11,
double m12)
m00 - the entry for the [0, 0] element in the transformation matrix
m01 - the entry for the [0, 1] element in the transformation matrix
m02 - the entry for the [0, 2] element in the transformation matrix
m10 - the entry for the [1, 0] element in the transformation matrix
m11 - the entry for the [1, 1] element in the transformation matrix
m12 - the entry for the [1, 2] element in the transformation matrix
public AffineTransformation(AffineTransformationtrans)
trans - the transformation to copy
public AffineTransformation(Coordinatesrc0, Coordinate src1, Coordinate src2, Coordinate dest0, Coordinate dest1, Coordinate dest2)
src0 - source point 0
src1 - source point 1
src2 - source point 2
dest0 - the mapped point for source point 0
dest1 - the mapped point for source point 1
dest2 - the mapped point for source point 2
public static AffineTransformationreflectionInstance(double x0, double y0, double x1, double y1)
x0 - the x-ordinate of a point on the reflection line
y0 - the y-ordinate of a point on the reflection line
x1 - the x-ordinate of a another point on the reflection line
y1 - the y-ordinate of a another point on the reflection line
public static AffineTransformationreflectionInstance(double x, double y)
x - the x-ordinate of a point on the reflection line
y - the y-ordinate of a point on the reflection line
public static AffineTransformationrotationInstance(double theta)
theta - the rotation angle, in radians
public static AffineTransformationrotationInstance(double sinTheta, double cosTheta)
sinTheta - the sine of the rotation angle
cosTheta - the cosine of the rotation angle
public static AffineTransformationrotationInstance(double theta, double x, double y)
theta - the rotation angle, in radians
x - the x-ordinate of the rotation point
y - the y-ordinate of the rotation point
public static AffineTransformationrotationInstance(double sinTheta, double cosTheta, double x, double y)
sinTheta - the sine of the rotation angle
cosTheta - the cosine of the rotation angle
x - the x-ordinate of the rotation point
y - the y-ordinate of the rotation point
public static AffineTransformationscaleInstance(double xScale, double yScale)
xScale - the value to scale by in the x direction
yScale - the value to scale by in the y direction
public static AffineTransformationscaleInstance(double xScale, double yScale, double x, double y)
xScale - the value to scale by in the x direction
yScale - the value to scale by in the y direction
x - the x-ordinate of the point to scale around
y - the y-ordinate of the point to scale around
public static AffineTransformationshearInstance(double xShear, double yShear)
xShear - the value to shear by in the x direction
yShear - the value to shear by in the y direction
public static AffineTransformationtranslationInstance(double x, double y)
x - the value to translate by in the x direction
y - the value to translate by in the y direction
public AffineTransformationsetToIdentity()
| 1 0 0 | | 0 1 0 | | 0 0 1 |
public AffineTransformationsetTransformation(double m00, double m01, double m02, double m10, double m11, double m12)
m00 - the entry for the [0, 0] element in the transformation matrix
m01 - the entry for the [0, 1] element in the transformation matrix
m02 - the entry for the [0, 2] element in the transformation matrix
m10 - the entry for the [1, 0] element in the transformation matrix
m11 - the entry for the [1, 1] element in the transformation matrix
m12 - the entry for the [1, 2] element in the transformation matrix
public AffineTransformationsetTransformation(AffineTransformation trans)
trans - a transformation to copy
public double[] getMatrixEntries()
m00, m01, m02, m10, m11, m12
public double getDeterminant()
If the determinant is zero, the transform is singular (not invertible), and operations which attempt to compute an inverse will throw a NoninvertibleTransformException.| m00 m01 m02 | | m10 m11 m12 | = m00 * m11 - m01 * m10 | 0 0 1 |
getInverse()
public AffineTransformationgetInverse() throws NoninvertibleTransformationException
The matrix of the inverse is equal to the inverse of the matrix for the transformation. It is computed as follows:
1
inverse(A) = --- x adjoint(A)
det
= 1 | m11 -m01 m01*m12-m02*m11 |
--- x | -m10 m00 -m00*m12+m10*m02 |
det | 0 0 m00*m11-m10*m01 |
= | m11/det -m01/det m01*m12-m02*m11/det |
| -m10/det m00/det -m00*m12+m10*m02/det |
| 0 0 1 |
NoninvertibleTransformationException -
getDeterminant()
public AffineTransformationsetToReflectionBasic(double x0, double y0, double x1, double y1)
x0 - the X ordinate of one point on the reflection line
y0 - the Y ordinate of one point on the reflection line
x1 - the X ordinate of another point on the reflection line
y1 - the Y ordinate of another point on the reflection line
public AffineTransformationsetToReflection(double x0, double y0, double x1, double y1)
x0 - the X ordinate of one point on the reflection line
y0 - the Y ordinate of one point on the reflection line
x1 - the X ordinate of another point on the reflection line
y1 - the Y ordinate of another point on the reflection line
public AffineTransformationsetToReflection(double x, double y)
d = sqrt(x2 + y2) sin = y / d; cos = x / d; Tref = Trot(sin, cos) x Tscale(1, -1) x Trot(-sin, cos)
x - the x-component of the reflection line vector
y - the y-component of the reflection line vector
public AffineTransformationsetToRotation(double theta)
| cos(theta) -sin(theta) 0 | | sin(theta) cos(theta) 0 | | 0 0 1 |
theta - the rotation angle, in radians
public AffineTransformationsetToRotation(double sinTheta, double cosTheta)
| cosTheta -sinTheta 0 | | sinTheta cosTheta 0 | | 0 0 1 |
sinTheta - the sine of the rotation angle
cosTheta - the cosine of the rotation angle
public AffineTransformationsetToRotation(double theta, double x, double y)
| cosTheta -sinTheta x-x*cos+y*sin | | sinTheta cosTheta y-x*sin-y*cos | | 0 0 1 |
theta - the rotation angle, in radians
x - the x-ordinate of the rotation point
y - the y-ordinate of the rotation point
public AffineTransformationsetToRotation(double sinTheta, double cosTheta, double x, double y)
| cosTheta -sinTheta x-x*cos+y*sin | | sinTheta cosTheta y-x*sin-y*cos | | 0 0 1 |
sinTheta - the sine of the rotation angle
cosTheta - the cosine of the rotation angle
x - the x-ordinate of the rotation point
y - the y-ordinate of the rotation point
public AffineTransformationsetToScale(double xScale, double yScale)
| xScale 0 dx | | 1 yScale dy | | 0 0 1 |
xScale - the amount to scale x-ordinates by
yScale - the amount to scale y-ordinates by
public AffineTransformationsetToShear(double xShear, double yShear)
Note that a shear of (1, 1) is not equal to shear(1, 0) composed with shear(0, 1). Instead, shear(1, 1) corresponds to a mapping onto the line x = y.| 1 xShear 0 | | yShear 1 0 | | 0 0 1 |
xShear - the x component to shear by
yShear - the y component to shear by
public AffineTransformationsetToTranslation(double dx, double dy)
| 1 0 dx | | 1 0 dy | | 0 0 1 |
dx - the x component to translate by
dy - the y component to translate by
public AffineTransformationreflect(double x0, double y0, double x1, double y1)
x0 - the x-ordinate of a point on the line to reflect around
y0 - the y-ordinate of a point on the line to reflect around
x1 - the x-ordinate of a point on the line to reflect around
y1 - the y-ordinate of a point on the line to reflect around
public AffineTransformationreflect(double x, double y)
x - the x-ordinate of the line to reflect around
y - the y-ordinate of the line to reflect around
public AffineTransformationrotate(double theta)
theta - the angle to rotate by, in radians
public AffineTransformationrotate(double sinTheta, double cosTheta)
sinTheta - the sine of the angle to rotate by
cosTheta - the cosine of the angle to rotate by
public AffineTransformationrotate(double theta, double x, double y)
theta - the angle to rotate by, in radians
x - the x-ordinate of the rotation point
y - the y-ordinate of the rotation point
public AffineTransformationrotate(double sinTheta, double cosTheta, double x, double y)
sinTheta - the sine of the angle to rotate by
cosTheta - the cosine of the angle to rotate by
x - the x-ordinate of the rotation point
y - the y-ordinate of the rotation point
public AffineTransformationscale(double xScale, double yScale)
xScale - the value to scale by in the x direction
yScale - the value to scale by in the y direction
public AffineTransformationshear(double xShear, double yShear)
xShear - the value to shear by in the x direction
yShear - the value to shear by in the y direction
public AffineTransformationtranslate(double x, double y)
x - the value to translate by in the x direction
y - the value to translate by in the y direction
public AffineTransformationcompose(AffineTransformation trans)
AffineTransformation. This produces a transformation whose effect is equal to applying this transformation followed by the argument transformation. Mathematically,
A.compose(B) = TB x TA
trans - an affine transformation
public AffineTransformationcomposeBefore(AffineTransformation trans)
AffineTransformation with this transformation. This produces a transformation whose effect is equal to applying the argument transformation followed by this transformation. Mathematically,
A.composeBefore(B) = TA x TB
trans - an affine transformation
public Coordinatetransform(Coordinate src, Coordinate dest)
src - the coordinate to transform
dest - the coordinate to accept the results
public Geometrytransform(Geometry g)
seq - a
Geometry
public void transform(CoordinateSequenceseq, int i)
seq - a
CoordinateSequence
i - the index of the coordinate to transform
public void filter(CoordinateSequenceseq, int i)
filter in interface
CoordinateSequenceFilter
seq - a
CoordinateSequence
i - the index of the coordinate to transform
public boolean isGeometryChanged()
CoordinateSequenceFilter
Geometry.geometryChanged() will be executed after this filter has finished being executed.
Most filters can simply return a constant value reflecting whether they are able to change the coordinates.
isGeometryChanged in interface
CoordinateSequenceFilter
public boolean isDone()
isDone in interface
CoordinateSequenceFilter
public boolean isIdentity()
public boolean equals(Objectobj)
public StringtoString()
AffineTransformation[[m00, m01, m02], [m10, m11, m12]]