05-05-2017, 05:51 PM
Find below two programs to convert from/to rectangular coordinates to/from spherical coordinates.
The variables of the calculator are preserved.
Only the stack is used.
Two programs are provided:
- rect2sph: XEQ S
- sph2rect: XEQ R
Cartesian coordinates are in the form (x, y, z)
Spherical coordinates are in the form (r, theta, phi),
where r is the radius/distance, theta is the azimuth, and phi is the elevation.
Formula used are:
x = r.cos(theta).cos(phi)
y = r.sin(theta).cos(phi)
z = r.sin(phi)
r = sqrt(x²+y²+z²)
theta = atan2(y, x)
phi = atan2(z, sqrt(x²+y²))
Usage for rect2sph:
Stack before:
Z: x
Y: y
X: z
Exec program: XEQ S
Stack after:
T: [x, y, z]
Z: r
Y: theta
X: phi
Usage for sph2rect:
Stack before:
Z: r
Y: theta
X: phi
Exec program: XEQ R
Stack after:
T: [r, theta, phi]
Z: x
Y: y
X: z
Code for rect2sph:
Code for sph2rect:
The variables of the calculator are preserved.
Only the stack is used.
Two programs are provided:
- rect2sph: XEQ S
- sph2rect: XEQ R
Cartesian coordinates are in the form (x, y, z)
Spherical coordinates are in the form (r, theta, phi),
where r is the radius/distance, theta is the azimuth, and phi is the elevation.
Formula used are:
x = r.cos(theta).cos(phi)
y = r.sin(theta).cos(phi)
z = r.sin(phi)
r = sqrt(x²+y²+z²)
theta = atan2(y, x)
phi = atan2(z, sqrt(x²+y²))
Usage for rect2sph:
Stack before:
Z: x
Y: y
X: z
Exec program: XEQ S
Stack after:
T: [x, y, z]
Z: r
Y: theta
X: phi
Usage for sph2rect:
Stack before:
Z: r
Y: theta
X: phi
Exec program: XEQ R
Stack after:
T: [r, theta, phi]
Z: x
Y: y
X: z
Code for rect2sph:
Code:
S001 LBL S
S002 [REGZ,REGY,REGX]
S003 ARG(REGT+REGZ*i) CK=7FF4 LN=16
S004 x<>y
S005 ARG(ABS(REGX*[1,0,0]+REGT*i)+REGZ*i) CK=D2C6 LN=36
S006 x<>y
S007 ENTER
S008 ABS
S009 Rdown
S010 Rdown
S011 RTN
CK=B926 LN=101
Code for sph2rect:
Code:
R001 LBL R
R002 [REGZ,REGY,REGX]
R003 Rup
R004 REGX*COS(REGT)*COS(REGZ) CK=C8A2 LN=24
R005 x<>y
R006 REGX*SIN(REGZ*[0,1,0])*COS(REGT) CK=7F3B LN=32
R007 x<>y
R008 Rdown
R009 REGT*SIN(REGZ*[0,0,1]) CK=33B2 LN=22
R010 RTN
CK=6852 LN=124