How to "rotate" points through 90 degree?

I am trying to do some intersection tests and so the math gets weird if two certain points have the same $x$ coordinate and so infinite slope. The points can be anywhere in any quadrant.

I want to "rotate" all my points through $90^o$ which will preserve what I need while making the math easier.

For a point $(x, y)$ is it just changing it to $(y, x)$?


Solution 1:

No: replace $(x, y)$ with $(-y, x)$. That will rotate 90 degrees counterclockwise about the origin.

What you proposed will flip everything around a 45-degree line that runs from southeast to northwest.

BTW: To rotate clockwise, replace $(x, y)$ with $(y, -x)$.

Solution 2:

If you represent the point $(x,y)$ in the plane as a complex number $x+iy$, then multiplying it by $i$ rotates it $90^\circ$ counterclockwise and multiplying it by $-i$ rotates it $90^\circ$ clockwise.