Trigonomectric constants Polar and spherical to rectangular coordinates transform

Dependents:   DISCO-F746NG_Lidar ZAILLEL_Interface

Trigo.cpp

Committer:
cromda
Date:
2012-11-25
Revision:
1:eb028056d162
Parent:
0:2f533ad7c611
Child:
4:a6b0fd2c4f85

File content as of revision 1:eb028056d162:

#include "mbed.h"
#include "Trigo.h"

// Trigo Library
// trogonometric 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);
}