Trigonomectric constants Polar and spherical to rectangular coordinates transform
Dependents: DISCO-F746NG_Lidar ZAILLEL_Interface
Diff: Trigo.cpp
- Revision:
- 5:b07cac89c306
- Parent:
- 4:a6b0fd2c4f85
diff -r a6b0fd2c4f85 -r b07cac89c306 Trigo.cpp --- a/Trigo.cpp Mon Nov 26 20:40:51 2012 +0000 +++ b/Trigo.cpp Sat Dec 08 21:54:57 2012 +0000 @@ -1,40 +1,52 @@ -#include "mbed.h" -#include "Trigo.h" - -// Trigo Library -// trigonometric constants and utilities -// rémi cormier 2012 - -void RecPol(float x, float y, float *r, float *a) -{*r=sqrt(x*x+y*y); -if (x==0.0) - {if (y==0.0) - {*a=0.0;} - else - {if (y>=0.0) - {*a=halfPi;} - else - {*a=-halfPi;}}} -else - {*a=atan(y/x); - if(x<0) - {*a=Pi+*a;} - if (*a>Pi) - {*a=*a-twoPi;} - } -} - -void PolRec(float r, float a, float *x, float *y) -{*x=r*cos(a); - *y=r*sin(a); -} - -void RecSph(float x, float y, float z, float *r, float *a, float *b) -{RecPol(x,y,b,a); - RecPol(*b,z,r,b); -} - -void SphRec(float r, float a, float b, float *x, float *y, float *z) -{PolRec(r,b,x,z); - PolRec(*x,a,x,y); -} \ No newline at end of file +#include "mbed.h" +#include "Trigo.h" + +// Trigo Library +// trigonometric constants and utilities +// rémi cormier 2012 + +void RecPol(float x, float y, float *r, float *a) +{*r=sqrt(x*x+y*y); +if (x==0.0) + {if (y==0.0) + {*a=0.0;} + else + {if (y>=0.0) + {*a=halfPi;} + else + {*a=-halfPi;}}} +else + {*a=atan(y/x); + if(x<0) + {*a=Pi+*a;} + if (*a>Pi) + {*a=*a-twoPi;} + } +} + +void PolRec(float r, float a, float *x, float *y) +{*x=r*cos(a); + *y=r*sin(a); +} + +void RecSph(float x, float y, float z, float *r, float *a, float *b) +{RecPol(x,y,b,a); + RecPol(*b,z,r,b); +} + +void SphRec(float r, float a, float b, float *x, float *y, float *z) +{PolRec(r,b,x,z); + PolRec(*x,a,x,y); +} + +float dm2dec(float dm) + {float s; + if (dm<0) + {dm=-dm; + s=-1;} + else + {s=1;} + float deg=floor(dm/100); + dm=dm-deg*100; + return(s*(deg+dm/60)); + } \ No newline at end of file