Trigonomectric constants Polar and spherical to rectangular coordinates transform

Dependents:   DISCO-F746NG_Lidar ZAILLEL_Interface

Trigo.h

Committer:
cromda
Date:
2012-11-25
Revision:
3:7b8333402db0
Parent:
2:fe695d6c9c83
Child:
4:a6b0fd2c4f85

File content as of revision 3:7b8333402db0:

#ifndef MBED_TRIGO_H
#define MBED_TRIGO_H

// Trigo Library
// trogonometric constants and utilities
// rémi cormier 2012


const float Pi=3.141592653590;
const float halfPi=Pi/2.0;
const float twoPi=2.0*Pi;
const float degre=Pi/180.0;// radian

// rectangular (x,y) to polar coordinates (r : radius, a : angle) transform
// a is the angle (radian, counter clockwise), with origin on x axis 
// -pi <= a <= pi
void RecPol(float x, float y, float *r, float *a);

// polar (r : radius, a : angle (rd))) to rectangular (x,y) transform
void PolRec(float r, float a, float *x, float *y);

// Rectangular (x,y,z) to sphérical (r : radius, a : angle, b : angle)
// a is the angle (radian, counter clockwise) betwen the projection of (x,y,z) on xy plane and the x axis
// -pi <= a <= pi
// b is the angle (radian, counter clockwise) betwen (x,y,z) and the xy plane
// -pi/2 <= b <= pi/2
void RecSph(float x, float y, float z, float *r, float *a, float *b);

void SphRec(float r, float a, float b, float *x, float *y, float *z);

#endif


/*      SAMPLE CODE ****************
#include "mbed.h"
#include "Trigo.h"

Serial pc(USBTX, USBRX);

const float Dmax = 1.0;
float N = 1;
const float pas=Dmax/N;
float X;
float Y;
float Z;
float R;
float A;
float B;

int main() {
// print pi do PC
pc.printf("pi = %.9f\n\r",Pi);

// Recpol dand PolRec test
pc.printf("RecPol et PolRec\n\r");

for(float i=-N; i<=N; i+=1)
{
 for (float j=-N; j<=N;j+=1)
{X=i*pas;
 Y=j*pas;
 RecPol(X,Y,&R,&A);
 pc.printf("X : %+.9f Y : %+.9f R : %+.9f A : %+9.4f\n\r",X,Y,R,A/degre);
 PolRec(R,A,&X,&Y);
 pc.printf("X : %+.9f Y : %+.9f R : %+.9f A : %+9.4f\n\r",X,Y,R,A/degre);
}}
pc.printf("\n\r");

// RecSph and SphRec test
pc.printf("RecSph et SphRec\n\r");

for (float i=-N;i<=N;i+=1)
    {for (float j=-N;j<=N;j+=1)
        {for (float k=-N;k<=N;k+=1)
            {X=i*pas;
             Y=j*pas;
             Z=k*pas;
             RecSph(X,Y,Z,&R,&A,&B);
             pc.printf("X : %+.9f Y : %+.9f Z : %+.9f R : %+.9f A : %+9.4f B : %+9.4f\n\r",X,Y,Z,R,A/degre,B/degre);
             SphRec(R,A,B,&X,&Y,&Z);
             pc.printf("X : %+.9f Y : %+.9f Z : %+.9f R : %+.9f A : %+9.4f B : %+9.4f\n\r",X,Y,Z,R,A/degre,B/degre);
            }
        }
    }


}

*/