getInverse method

AffineTransformation getInverse()

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.

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               |

@return a new inverse transformation @throws NoninvertibleTransformationException @see #getDeterminant()

Implementation

AffineTransformation getInverse() {
  double det = getDeterminant();
  if (det == 0) throw StateError("Transformation is non-invertible");

  double im00 = m11 / det;
  double im10 = -m10 / det;
  double im01 = -m01 / det;
  double im11 = m00 / det;
  double im02 = (m01 * m12 - m02 * m11) / det;
  double im12 = (-m00 * m12 + m10 * m02) / det;

  return AffineTransformation.fromMatrixValues(
      im00, im01, im02, im10, im11, im12);
}