The following warnings occurred:
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 795 - File: showthread.php PHP 7.4.33 (FreeBSD)
File Line Function
/showthread.php 795 errorHandler->error





Post Reply 
COS(X) dislpay wrong answer
09-01-2018, 11:46 PM (This post was last modified: 09-02-2018 02:28 AM by Magnus512.)
Post: #1
COS(X) dislpay wrong answer
So I'm writing a code to change between coordinate systems, this is the code
-------------------------------------
EXPORT SPHERE,RECTAN,CYLIN;
//Rectangular to Spherical
//(x,y,z)-->(ρ,θ,φ)
EXPORT RECT2SPHE(CORD)
BEGIN
//Separacion de coordenadas en x,y y z.
LOCAL x:=CORD(1),y:=CORD(2),z:=CORD(3);
//Variables para guardar resultado temporal
LOCAL ρ,θ,φ,result;
//Operaciones para convertir los valores
ρ:=SQRT(x^2+y^2+z^2);
θ:=atan2(y/x);
φ:=ACOS(z/ρ);
//Guardar el resultado en la variable global SPHERE
SPHERE:=[ρ,θ,φ];
RETURN("ρ="+ρ+" θ="+θ+" φ="+φ);
END;

//Spherical to Rectangular
//(ρ,θ,φ)-->(x,y,z)
EXPORT SPHE2RECT(CORD)
BEGIN
//Separacion de cordenadas en r,θ y φ.
LOCAL ρ:=CORD(1),θ:=CORD(2),φ:=CORD(3);
//Variables para guardar resultado temporal
LOCAL x,y,z,result;
x:=ρ*SIN(φ)*COS(θ);
y:=ρ*SIN(φ)*SIN(θ);
z:=ρ*COS(φ);
//Guardar el resultado en la variable global RECTAN
RECTAN:=[x,y,z];
RETURN("x="+x+" y="+y+" z="+z);
END;

//Rectangular to Cylindrical
//(x,y,z)-->(r,θ,z)
EXPORT RECT2CYL(CORD)
BEGIN
//Separacion de coordenadas en x,y y z.
LOCAL x:=CORD(1),y:=CORD(2),z:=CORD(3);
//Variables para guardar resultado temporal
LOCAL r,θ,result;
r:=SQRT(x^2+y^2);
θ:=atan2(y,x);
z:=z;
//Guardar el resultado en la variable global CYLIN
CYLIN:=[r,θ,z];
RETURN("r="+r+" θ="+θ+" z="+z);
END;

//Cylindrical to Rectangular
//(r,θ,z)-->(x,y,z)
EXPORT CYL2RECT(CORD)
BEGIN
//Separacion de coordenadas en r,θ y z.
LOCAL r:=CORD(1),θ:=CORD(2),z:=CORD(3);
//Variables para guardar resultado temporal
LOCAL x,y,result;
x:=r*COS(θ);
y:=r*SIN(θ);
z:=z;
//Guardar el resultado en la variable global RECTAN
RECTAN:=[x,y,z];
RETURN("x="+x+" y="+y+" z="+z);
END;

//Spherical to Cylindrical
//(ρ,θ,φ)-->(r,θ,z)
EXPORT SPHE2CYL(CORD)
BEGIN
//Separacion de coordenadas en (ρ,θ,φ)
LOCAL ρ:=CORD(1),θ:=CORD(2),φ:=CORD(3);
//Variables para guardar resultado temporal
LOCAL r,z,result;
r:=ρ*SIN(φ);
θ:=θ;
z:=ρ*COS(φ);
//Guardar el resultado en la variable global CYLIN
CYLIN:=[r,θ,z];
RETURN("r="+r+" θ="+θ+" z="+z);
END;

//Cylindrical to Spherical
//(r,θ,z)-->(ρ,θ,φ)
EXPORT CYL2SPHE(CORD)
BEGIN
//Separacion de coordenadas en r,θ y z.
LOCAL r:=CORD(1),θ:=CORD(2),z:=CORD(3);
//Variables para guardar resultado temporal
LOCAL ρ,φ,result;
ρ:=SQRT(r^2+z^2);
θ:=θ;
φ:=atan2(r,z);
//Guardar el resultado en la variable global SPHERE
SPHERE:=[ρ,θ,φ];
RETURN("ρ="+ρ+" θ="+θ+" φ="+φ);
END;
------------------------------------
....
So when I convert from Rectangular to Cylindrical in radian mode the "error" comes out, I convert to Cylindrical and take the result of the conversion and I pass it to the function that converts from Cylindrical to Rectangular and there it is I don't get the first input values I mean almost, I don't get 1 I get 1.0000000....
   
But when I work in degrees it works fine
   
So is this a Bug ? an internal error ? Or a mistake of mine ?
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
COS(X) dislpay wrong answer - Magnus512 - 09-01-2018 11:46 PM
RE: COS(X) dislpay wrong answer - JMB - 09-02-2018, 01:02 PM



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