I introduced a Small Basic sample code about 2-dimensional vector in my last blog. A 2-D vector has two elements. A point in the plane has x coordinate and y coordinate. This kind of coordinate is called Cartesian coordinates.
Today, I’d like to introduce another coordinate system – polar coordinates. In polar coordinates, a point is represented with r (the length from the origin) and θ (the angle between the vector and the x axis). A sample program TJB764 shows both coordinates.
Conversion from polar coordinates to Cartesian coordinates
This is easy.
Small Basic code is as follows. A variable a means θ above.
Conversion from Cartesian coordinates to polar coodinates
This is basically easy.
Small Basic code is:
I already wrote about this subroutine in this blog titled Small Basic Game Programming – Game Math. But the last one causes divide by zero error in Small Basic 1.2.
Math function tan-1 is Math.ArcTan() operation in Small Basic. The graph of this operation is: