How To Properly...

Rotate Points using Polar Coordinates

If you have ever tried to homebrew a software 3d graphics engine, or design a graphics cpu, you may be prone to overzealousness. Being so, you may well have been unsure of how you’re supposed to properly transform a set of 3-dimensional coordinates onto a rotation-capable viewport. Furthermore… objects should rotate, it’s just natural.

The solution I found to rotation, as long ago I pressured my TI-83 into producing 3d images, is polar coordinates.

Rectangular Coordinates

Rectangular Coordinates

Rectangular coordinates are the sort you are probably familiar with, involving the distances of a point from planes x and y. Given distance x and distance y you can locate a point in a two dimensional space relative to an index point (origin), where both x and y are zero.

Polar Coordinates

The polar coordinate scheme involves, instead of x and y coordinates:

  1. r, the distance from the origin, measured by one straight line directly from the origin, to the point
  2. q, the angle formed by that line and the x axis.
Polar Coordinates

As you increase the angle q the point is made to rotate counter-clockwise around the origin. As the point is rotated by q it remains at distance r from the origin.

Give Me an Example

Imagine a 2-dimensional coordinate in x, y (rectangular) form, where x = 30 and y = 0. As y = 0, the point lies on the x axis, so the angle q measures 0. The distance r = 30 in this case because the point is 30 units of measure away from the origin, just along the x axis.

A new rectangular point (0,20) is a distance of 20 units away from the origin, and the angle q is 90 degrees, 1/4 of a full rotation.

How to Convert

First, make the origin the point of rotation by performing what is called a transformation: placing a new origin and adjusting all of the coordinates to reflect their new spatial relationship to the origin.

You may then apply to your coordinates the rule of Pythagoras to determine the distance from the origin to the point. r = the square root of x2+y2.

And the angle q = tan-1(y/x).

Rotation

Once you have your polar coordinates r and q, you can perform rotation by operating on the value q, minding the format (Degrees, radians, other…) your platform uses for angle measurements.

Converting Back into Rectangular Space

In rectangular coordinates x = r cos(q), and y = r sin(q), where r and q are, respectively, your point’s distance from the origin and newly adjusted q degree of rotation.

Q. What else can I do with polar coordinates?

A. Scaling!