HP Forums
Coordinate Converter Ultimate - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (/forum-10.html)
+--- Forum: HP Prime Software Library (/forum-15.html)
+--- Thread: Coordinate Converter Ultimate (/thread-7041.html)



Coordinate Converter Ultimate - BERNARD MICHAUD - 10-15-2016 01:27 AM

Update May 27-2017 to include FORMATTED CODE.


CoorConvUlt is yet another converter which when one system is entered(Cart., Cyl. or Sph), the other two system are simultaneously converted and all three system are displayed along with the graph showing the position of each variables on the graph. If you discover errors please feel free to point them out so further correction can be made. Thank you.[/code]

Coorconv();
quit();
//----------------------

quit()
BEGIN
PRINT();
PRINT("


Coord. Conv. Ult_2.

B. M.

Oct. 18,2016");

END;


Coorconv()
BEGIN
LOCAL OP3:=0;
LOCAL ρ:=0,Θ:=0,θ:=0,z:=0;
LOCAL X:=0,Y:=0,Z:=0,r:=0,φ:=0;
INPUT({
{X,[0],{10,20,1}},{Y,[0],{10,20,3}},{Z,[0],{10,20,5}},
{ρ,[0],{40,20,1}},{θ,[0],{40,20,3}},{z,[0],{41,20,5}},
{r,[0],{70,20,1}},{Θ,[0],{71,20,3}},{φ,[0],{70,20,5}}},
"Cartesian Cylindrical Spherical",{
"X = ","Y = ","Z =",
"ρ = ","θ = ","Z = ",
"r = ","θ = ","φ ="},
{
" Enter a value for X.",
" Enter a value for Y.",
" Enter a value for Z.",
" Enter a value for ρ.",
" Enter a value for θ.",
" Enter a value for Z.",
" Enter a value for r.",
" Enter a value for θ.",
" Enter a value for φ."});
//-------------------------
//Cart->Cyl->Sph
IF ρ==0 AND θ==0 AND z==0 AND r==0 AND φ==0 THEN

ρ:=√(X²+Y²);
θ:=ARG(X+Y*i);
z:=Z;

r:=√(X²+Y²+Z²);
θ:=ARG(X+Y*i);
φ:=ARG(Z+*√(X²+Y²));END;//28
//----------------------
//Cyl->Sph->Cart
IF r==0 AND Θ==0 AND φ==0 AND X==0 AND Y==0 AND Z==0 THEN

r:=√(ρ²+z²);
Θ:=θ;
φ:=ARG(z+ρ*i);

X:=ρ*COS(Θ);
Y:=ρ*SIN(Θ);
Z:=z;END;//39
//----------------------
//Sph->Cyl->Cart
IF ρ==0 AND θ==0 AND z==0 AND X==0 AND Y==0 AND Z==0THEN

ρ:=r*SIN(φ);
θ:=Θ;
z:=r*COS(φ);

X:=r*COS(Θ)*SIN(φ);
Y:=r*SIN(Θ)*SIN(φ);
Z:=r*COS(φ);END;//50
//---------------------


LOCAL green:=rgb(50,200,120),
white:=rgb(255,255,255),
black:=rgb(0,0,0),
red:=rgb(255,0,0),
copper:=rgb(220,0,0),
blue:=rgb(0,0,255),
coppr:=rgb(220,0,10);
DIMGROB_P(G1,320,240);
RECT(G1);

LOCAL k,D1,D2,D3,D4,D5,D6;
LOCAL C1,C2,C3,C4,C5,C6;
k:=0;
RECT;

REPEAT

k:=GETKEY;

LINE_P(G1,70,180,70,100,green);//L1
LINE_P(G1,70,180,30,220,green);//L2
LINE_P(G1,70,180,140,180,green);//L3

LINE_P(G1,70,180,100,140,red);//L4
LINE_P(G1,100,140,70,110,red);//L5
LINE_P(G1,100,140,100,210,red);//L6
LINE_P(G1,70,180,100,210,blue);//L7

LINE_P(G1,100,210,40,210,blue);//L8
LINE_P(G1,100,210,130,180,blue);//L9

TEXTOUT_P("Cartesian",G1,20,20,4,green);
TEXTOUT_P("Cylindrical",G1,170,40,4,blue);
TEXTOUT_P("Spherical",G1,170,140,4,red);
//Graph Data
TEXTOUT_P("X",G1,20,218,3,black);
TEXTOUT_P("Y",G1,145,173,3,black);
TEXTOUT_P("Z",G1,58,95,3,black);
TEXTOUT_P("r",G1,85,140,3,black);
TEXTOUT_P("φ",G1,70,155,3,black);
TEXTOUT_P("ρ",G1,85,180,3,black);
TEXTOUT_P("θ",G1,68,185,3,black);


TEXTOUT_P("ρ = ",G1,170,60,4,black);
TEXTOUT_P(ρ,G1,193,60,4,black);

TEXTOUT_P("θ = ",G1,170,80,4,black);
TEXTOUT_P(θ,G1,193,80,4,black);

TEXTOUT_P("Z = ",G1,170,100,4,black);
TEXTOUT_P(Z,G1,194,100,4,black);
//-----------------------------------
TEXTOUT_P("X = ",G1,20,40,4,black);
TEXTOUT_P(X,G1,43,40,4,black);

TEXTOUT_P("Y = ",G1,20,60,4,black);
TEXTOUT_P(Y,G1,43,60,4,black);

TEXTOUT_P("Z = ",G1,20,80,4,black);
TEXTOUT_P(Z,G1,43,80,4,black);
//------------------------------------
TEXTOUT_P("r = ",G1,170,160,4,black);
TEXTOUT_P(r,G1,194,160,4,black);

TEXTOUT_P("θ = ",G1,170,180,4,black);
TEXTOUT_P(θ,G1,193,180,4,black);

TEXTOUT_P("φ = ",G1,170,200,4,black);
TEXTOUT_P(φ,G1,194,200,4,black);
TEXTOUT_P("Exit? [Esc]_2x",G1,80,218,3,black);
//-------------------------------------
BLIT_P(G0,0,0,320,240,G1,0,0,320,240);
//-------------------------------------
//WAIT(1);
UNTIL k==4; // Esc


IFERR REPEAT UNTIL GETKEY>-1;
THEN
ELSE
CHOOSE(OP3,"Choose an Option? ",{"Repeat Calculation","Quit"});
CASE
IF OP3==1 THEN Coorconv();END;//here
IF OP3==2 THEN quit();END;
IF OP3==3 THEN IFERR BREAK; BREAK; THEN END END;//here
DEFAULT
END;
END;
END;


EXPORT newconvt()
BEGIN
Coorconv();
END;
[/php]