Coordinate Conversions: Rectangular, Cylindrical, Spherical
02-04-2014, 04:48 AM (This post was last modified: 05-01-2016 04:28 PM by Eddie W. Shore.)
Post: #1
 Eddie W. Shore Senior Member Posts: 1,358 Joined: Dec 2013
Coordinate Conversions: Rectangular, Cylindrical, Spherical
PLEASE SCROLL TO THE END OF THIS THREAD, the most recent version is there. Thanks,

Eddie

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
12-16-2014, 01:38 PM
Post: #2
 Eddie W. Shore Senior Member Posts: 1,358 Joined: Dec 2013
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. Hope to have a working solution soon. Eddie
12-16-2014, 02:11 PM (This post was last modified: 12-16-2014 02:27 PM by Han.)
Post: #3
 Han Senior Member Posts: 1,882 Joined: Dec 2013
RE: Coordinate Conversions: Rectangular, Cylindrical, Spherical
Change sqrt(-1) to lower-case i (and ensure lower-case i is not declared as a local variable); or use the "i" character [Shift][3]. This will work around the possibility that users may not have enabled complex output from real input (page 1 in the Home settings).

Graph 3D | QPI | SolveSys
12-17-2014, 05:05 AM
Post: #4
 Eddie W. Shore Senior Member Posts: 1,358 Joined: Dec 2013
RE: Coordinate Conversions: Rectangular, Cylindrical, Spherical
(12-16-2014 02:11 PM)Han Wrote:  Change sqrt(-1) to lower-case i (and ensure lower-case i is not declared as a local variable); or use the "i" character [Shift][3]. This will work around the possibility that users may not have enabled complex output from real input (page 1 in the Home settings).

Thanks, Han. I works better now.

Code:
OK try this, use the lowercase "i" instead of the "i" from [Shift]+[3] or sqrt(-1). Seems to work. Please let me know. Thanks Luigi.  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*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;
03-23-2016, 11:13 PM
Post: #5
 BERNARD MICHAUD Member Posts: 149 Joined: Aug 2015
RE: Coordinate Conversions: Rectangular, Cylindrical, Spherical
I notice that in the section below "ρ*COS(θ)];" should theta be replaced with 'phi'.
I tried X=8, Y=6, Z=4 it returns 10.77, 68.2, 36.87. Working it in reverse = 8, 6, 8.62.
That's 8.62 instead of 4.

IF ch==6 THEN
INPUT({ρ,θ,φ});
RETURN [ρ*COS(θ)*SIN(φ),ρ*SIN(θ)*SIN(φ),
ρ*COS(θ)];
END;
05-01-2016, 04:26 PM
Post: #6
 Eddie W. Shore Senior Member Posts: 1,358 Joined: Dec 2013
RE: Coordinate Conversions: Rectangular, Cylindrical, Spherical
Thank you Bernard.

The corrected program below:
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;
10-03-2016, 11:51 PM
Post: #7
 BERNARD MICHAUD Member Posts: 149 Joined: Aug 2015
RE: Coordinate Conversions: Rectangular, Cylindrical, Spherical
Sorry Eddie if I misled you. What I mean is this. You have the first section below, but should be the second section. ρ*COS(θ)]; should be ρ*COS(φ)];

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

Second section
IF ch==6 THEN
INPUT({ρ,θ,φ});
RETURN [ρ*COS(θ)*SIN(φ),ρ*SIN(θ)*SIN(φ),
ρ*COS(φ)]; correct
END;
 « Next Oldest | Next Newest »

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