This article contains a sample program for Math.Sin(), Math.Cos() and Math.ArcTan() operations.
Subroutine Math_PolarToCartesian() uses Math.Sin() and Math.Cos() operations to calculate Cartesian coordinate from polar coordinate.
Sub
Math_PolarToCartesian
' Math | convert polar coordinate to Cartesian coordinate
' param r, a - polar Coordinate
' return x, y - Cartesian coordinate
_a
=
Math
.
GetRadians
(
a
)
x
r
*
Cos
y
Sin
EndSub
Subroutine Math_CartesianToPolar() uses Math.ArcTan() operation to calculate polar coordinate from Cartesian coordinate.
Math_CartesianToPolar
' Math | convert Cartesian coordinate to polar coordinate
' param x, y - Cartesian coordinate
' return r, a - polar Coordinate (0<=a<360)
SquareRoot
+
If
0
And
>
Then
90
' [degree]
ElseIf
<
-
Else
ArcTan
/
180
Pi
EndIf
' at this point -90<=a<=90
360
' at this point 0<=a<360
Program JXB040 is a test code for these subroutines above. The usage is just moving mouse on the program window. The top x, y are got by Mouse.X and Mouse.Y . The second r and a are calculated with Math_CartesianToPolar(). The last x and y are calculated with Math_PolarToCartesian().