0

I'm looking for a function that takes the arguments: (x, y, m, n, rot) where rot%90 always equals 0.

And outputs equivalent coordinates x, y from a matrix of dimensions m, n in the same matrix rotated by rot degrees.

For example, given (x=0, y=0, m=3, n=3, rot=90) it would output [2, 0].

In other words - the top left would move to the top right.

I tried using matrix rotations but these aren't of use here since I'm rotating around the center of an array - at the very least they'd need some manipulation.

Rory McDonald
  • 253
  • 2
  • 8
  • 1
    This is not matrix rotation in the linear algebra sense. Since `rot % 90` is always 0, there are only four possible values. You can just handle the four cases separately. – Raymond Chen Oct 18 '22 at 18:33
  • Thanks, I suppose this is the most efficient way to do it. – Rory McDonald Oct 18 '22 at 18:37
  • Seems like these expressions will be useful: `[n-1-r, c]`, `[n-1-r, m-1-c]`, `[r, m-1-c]` – danh Oct 18 '22 at 18:40
  • @danh this was indeed the same solution I arrived at (except in reverse order for my case). – Rory McDonald Oct 18 '22 at 20:58
  • see [Rotate a diagonal line in a 2D 3 x 3 grid - rotation matrix needed?](https://stackoverflow.com/a/40355825/2521214) its about rotating ASCII art however the core rotation technique is the same for number matrix (just ignore the ASCI rotations) – Spektre Oct 19 '22 at 06:55

0 Answers0