Post Reply 
Coordinate Conversions: Rectangular, Cylindrical, Spherical
12-16-2014, 01:38 PM
Post: #2
RE: Coordinate Conversions: Rectangular, Cylindrical, Spherical
(02-04-2014 04:48 AM)Eddie W. Shore Wrote:  
Code:
EXPORT COORDCONV()
BEGIN
// 2014-02-03 EWS
// 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*√(-1)),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*√(-1)),θ];
END;

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

IF ch==5 THEN
INPUT({X,Y,Z});
RETURN [√(X²+Y²+Z²),
ARG(Z+√(-1)*√(X²+Y²)),ARG(X+√(-1)*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


** PLEASE IGNORE THIS PROGRAM - There is a problem with one of the commands (ARG) - apologizes for any inconvenience. Sad Hope to have a working solution soon. Eddie
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Coordinate Conversions: Rectangular, Cylindrical, Spherical - Eddie W. Shore - 12-16-2014 01:38 PM



User(s) browsing this thread: 1 Guest(s)