AffineTransform translation or scaling

Anybody know the correct way to determine if an AffineTransform is just a translation, a scaling operation, or both? In other words, how can I check if a transformed rectangle is still axis-aligned?


Mathematically the AffineTransform contains all possible transformations:

  • rotation
  • scale
  • translation

You can figure out from the coefficients. I think some convenience methods would be in order,
one exists: isOnlyTranslation()

Another one would be:

bool isRotation() const
    return (mat01 == 0.0 && mat10 == 0.0) == false;

(using the correct valuetype and avoiding equality checks for floating point for numerical reasons is left as an exercise for the reader)

For your Rectangle problem, you would need to transform the individual points and check if the differences lign up:

if ((topRight - topLeft).y == 0.0f)

…and so on…

Hope that helps


Thanks; that’s very helpful.