6

If I have a point and a Matrix:

float point[] = new float[]{x,y};
Matrix matrix = new Matrix();

and call:

matrix.mapPoints(point);

how could I reverse the effects that matrix.mapPoints(point) has on point?

This isn't the actual application that I will use the answer for, but an answer for this will would work for what I need.

Thanks for any help.

raystubbs
  • 193
  • 4
  • 7

1 Answers1

9

If you don't want yourMatrix to change

 Matrix inverseCopy = new Matrix();
 if(yourMatrix.invert(inverseCopy)){
      inverseCopy.mapPoints(transformedPoint);
      //Now transformedPoint is reverted to original state.
 }

If you want yourMatrix to change

 if(yourMatrix.invert(yourMatrix)){
      yourMatrix.mapPoints(transformedPoint);
      //Now transformedPoint is reverted to original state.
 }

matrix.invert() returns false if the matrix cannot be inverted. If your matrix cannot be inverted there is no way to revert your points to original state.

Durgadass S
  • 1,098
  • 6
  • 13
  • 1
    The second part of the answer is wrong, `yourMatrix.invert(null)` results in a `NullPointerException`. We need to pass a matrix in which the inverse will be stored. – Devansh Maurya Dec 24 '21 at 03:09