Rectpolar (dest, source) – Campbell Scientific CR5000 Measurement and Control Module User Manual
Page 196

Section 8. Processing and Math Instructions
8-24
RectPolar (Dest, Source)
Converts from rectangular to polar coordinates.
Parameter
& Data Type
Enter
Dest
Variable
array
Variable array in which to store the 2 resultant values. The length of the
vector is stored in the specified destination element and the angle, in
radians(±
π
), in the next element of the array
Source
Variable
Array
The variable array containing the X and Y coordinates to convert to Polar
coordinates. The X value must be in the specified array element and the Y
value in the next element of the array.
Example: In the following example, a counter (Deg) is incremented from 0 to
360 degrees. The cosine and sine of the angle are taken to get X and Y in
rectangular coordinates. RectPolar is then used to convert to polar coordinates.
Dim XY(2),Polar(2),Deg,AnglDeg
Const Pi=4*ATN(1)
Alias XY(1)=X
Alias XY(2)=Y
Alias Polar(1)=Length
Alias Polar(2)=AnglRad
DataTable(RtoP,1,500)
Sample(1,Deg,IEEE4)
Sample(2,XY,IEEE4)
Sample(2,Polar,IEEE4)
Sample(1,AnglDeg,IEEE4)
EndTable
BeginProg
For Deg=0 to 360
XY(1)=Cos(Deg*Pi/180)
‘Cos and Sin operate on radians
XY(2)=Sin(Deg*Pi/180)
RectPolar(Polar,XY)
AnglDeg=Polar(2)*180/Pi
‘Convert angle to degrees for
comparison w/Deg
CallTable RtoP
Next Deg
EndProg