Trigonomectric constants Polar and spherical to rectangular coordinates transform

Dependents:   DISCO-F746NG_Lidar ZAILLEL_Interface

Committer:
cromda
Date:
Sat Dec 08 21:54:57 2012 +0000
Revision:
5:b07cac89c306
Parent:
4:a6b0fd2c4f85
Add dm2dec function

Who changed what in which revision?

UserRevisionLine numberNew contents of line
cromda 5:b07cac89c306 1 #include "mbed.h"
cromda 5:b07cac89c306 2 #include "Trigo.h"
cromda 5:b07cac89c306 3
cromda 5:b07cac89c306 4 // Trigo Library
cromda 5:b07cac89c306 5 // trigonometric constants and utilities
cromda 5:b07cac89c306 6 // rémi cormier 2012
cromda 5:b07cac89c306 7
cromda 5:b07cac89c306 8 void RecPol(float x, float y, float *r, float *a)
cromda 5:b07cac89c306 9 {*r=sqrt(x*x+y*y);
cromda 5:b07cac89c306 10 if (x==0.0)
cromda 5:b07cac89c306 11 {if (y==0.0)
cromda 5:b07cac89c306 12 {*a=0.0;}
cromda 5:b07cac89c306 13 else
cromda 5:b07cac89c306 14 {if (y>=0.0)
cromda 5:b07cac89c306 15 {*a=halfPi;}
cromda 5:b07cac89c306 16 else
cromda 5:b07cac89c306 17 {*a=-halfPi;}}}
cromda 5:b07cac89c306 18 else
cromda 5:b07cac89c306 19 {*a=atan(y/x);
cromda 5:b07cac89c306 20 if(x<0)
cromda 5:b07cac89c306 21 {*a=Pi+*a;}
cromda 5:b07cac89c306 22 if (*a>Pi)
cromda 5:b07cac89c306 23 {*a=*a-twoPi;}
cromda 5:b07cac89c306 24 }
cromda 5:b07cac89c306 25 }
cromda 5:b07cac89c306 26
cromda 5:b07cac89c306 27 void PolRec(float r, float a, float *x, float *y)
cromda 5:b07cac89c306 28 {*x=r*cos(a);
cromda 5:b07cac89c306 29 *y=r*sin(a);
cromda 5:b07cac89c306 30 }
cromda 5:b07cac89c306 31
cromda 5:b07cac89c306 32 void RecSph(float x, float y, float z, float *r, float *a, float *b)
cromda 5:b07cac89c306 33 {RecPol(x,y,b,a);
cromda 5:b07cac89c306 34 RecPol(*b,z,r,b);
cromda 5:b07cac89c306 35 }
cromda 5:b07cac89c306 36
cromda 5:b07cac89c306 37 void SphRec(float r, float a, float b, float *x, float *y, float *z)
cromda 5:b07cac89c306 38 {PolRec(r,b,x,z);
cromda 5:b07cac89c306 39 PolRec(*x,a,x,y);
cromda 5:b07cac89c306 40 }
cromda 5:b07cac89c306 41
cromda 5:b07cac89c306 42 float dm2dec(float dm)
cromda 5:b07cac89c306 43 {float s;
cromda 5:b07cac89c306 44 if (dm<0)
cromda 5:b07cac89c306 45 {dm=-dm;
cromda 5:b07cac89c306 46 s=-1;}
cromda 5:b07cac89c306 47 else
cromda 5:b07cac89c306 48 {s=1;}
cromda 5:b07cac89c306 49 float deg=floor(dm/100);
cromda 5:b07cac89c306 50 dm=dm-deg*100;
cromda 5:b07cac89c306 51 return(s*(deg+dm/60));
cromda 5:b07cac89c306 52 }