Forum

Rotate a Rectangle

Hi everyone,
I am looking for a node or for a solution to rotate a rectangle. I know I can only transform 2D-Forms if they are a matrix. Saying so, I converted my rectangle to a matrix, tried to rotate it and convert the matrix back to a rectangle. But when I do this, the only thing which happens is it scales my rectangle.

Do you have any tipps?
Thanks

The Rectangle data type is axis-aligned, it is not able to encode all information of a rotated rectangle.

It depends on the use case, but I can think of different encodings:

  • a Path: it would store all points. It should have a hit test check. It’s the multipurpose solution that could eventually also be used for other 2D shapes.
  • a new custom datatype that bundles a Rectangle and a Rotation value
  • a Matrix representing the transformation that turns a Unit-Quad into particular rotated Rectangle. Such a transformation can be created with ToQuadTransformation. For hittests you could also store the object inverse transformation. With it you could take a mouse position and get it into the Unit-Quad-Space. If the mouse position is between -0.5…0.5 it’s inside your rotated rectangle.

But as always the best approach depends on what’s next on your wishlist.