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 |
This produces a transformation whose effect is that of A followed by B. The methods reflect, rotate, scale, shear, and translate have the effect of composing a transformation of that type with the transformation they are invoked on.A.compose(B) = TB x TA
The composition of transformations is in general not commutative.
| 1 0 0 | | 0 1 0 | | 0 0 1 |
m00, m01, m02, m10, m11, m12
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 |
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 |
d = sqrt(x2 + y2) sin = y / d; cos = x / d; Tref = Trot(sin, cos) x Tscale(1, -1) x Trot(-sin, cos)
| cos(theta) -sin(theta) 0 | | sin(theta) cos(theta) 0 | | 0 0 1 |
| cosTheta -sinTheta 0 | | sinTheta cosTheta 0 | | 0 0 1 |
| cosTheta -sinTheta x-x*cos+y*sin | | sinTheta cosTheta y-x*sin-y*cos | | 0 0 1 |
| cosTheta -sinTheta x-x*cos+y*sin | | sinTheta cosTheta y-x*sin-y*cos | | 0 0 1 |
| xScale 0 dx | | 1 yScale dy | | 0 0 1 |
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 |
| 1 0 dx | | 1 0 dy | | 0 0 1 |
A.compose(B) = TB x TA
A.composeBefore(B) = TA x TB
Geometry
CoordinateSequence
CoordinateSequence
AffineTransformation[[m00, m01, m02], [m10, m11, m12]]