Coordinate Conversions: Rectangular, Cylindrical, Spherical

+- HP Forums (http://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (/forum-10.html)
+--- Forum: HP Prime Software Library (/forum-15.html)
+--- Thread: Coordinate Conversions: Rectangular, Cylindrical, Spherical (/thread-610.html)



Coordinate Conversions: Rectangular, Cylindrical, Spherical - Eddie W. Shore - 02-03-2014 11:48 PM

Code:
EXPORT COORDCONV()
BEGIN
// 2014-02-03 EWS
// updated 2016-05-01
// Source: CRC

LOCAL ch,X,Y,Z,R;
LOCAL θ,ρ,φ;

CHOOSE(ch,"Coord. Conv.","Cart→Cyl",
"Cyl→Cart","Cyl→Sph","Sph→Cyl",
"Cart→Sph","Sph→Cart");

CASE

IF ch==1 THEN 
INPUT({X,Y,Z});
RETURN [√(X²+Y²),ARG(X+Y*i),Z];
END;

IF ch==2 THEN 
INPUT({R,θ,Z});
RETURN [R*COS(θ),R*SIN(θ),Z]; END;

IF ch==3 THEN
INPUT({R,θ,Z});
RETURN [√(R²+Z²),ARG(Z+R*i),θ];
END;

IF ch==4 THEN
INPUT({ρ,φ,θ});
RETURN [ρ*SIN(φ),θ,ρ*COS(φ)];
END;

IF ch==5 THEN
INPUT({X,Y,Z});
RETURN [√(X²+Y²+Z²),
ARG(Z+*√(X²+Y²)),ARG(X+i*Y)];
END;

IF ch==6 THEN
INPUT({ρ,θ,φ});
RETURN [ρ*COS(θ)*SIN(φ),ρ*SIN(θ)*SIN(φ),
ρ*COS(θ)];
END;

DEFAULT
RETURN "CANCELLED";
END;

END;

Note: Sqrt(-1) is that "I" character (Shift+3).

Eddie