| 1 |
#include <stdlib.h> |
| 2 |
#include <math.h> |
| 3 |
#include "gplaut04.h" |
| 4 |
|
| 5 |
extern UserData clientData; |
| 6 |
|
| 7 |
//////////////////////////////////////////////////////////////////////////////////// |
| 8 |
// |
| 9 |
void |
| 10 |
computePrimaryPositionInInertialSystem(int whichCenter, float mass, float R, float T, float t, |
| 11 |
float bigPosition[], float smallPosition[], float velocity[]) |
| 12 |
// |
| 13 |
//////////////////////////////////////////////////////////////////////////////////// |
| 14 |
{ |
| 15 |
float OMEGA = 2.0*M_PI; |
| 16 |
float ot = OMEGA*t; |
| 17 |
float alpha; |
| 18 |
if( whichCenter == INERTIAL_B) |
| 19 |
{ |
| 20 |
alpha = mass; |
| 21 |
} |
| 22 |
else if(whichCenter == INERTIAL_S ) |
| 23 |
{ |
| 24 |
alpha = 0; |
| 25 |
} |
| 26 |
else |
| 27 |
{ |
| 28 |
alpha = 1; |
| 29 |
} |
| 30 |
bigPosition[0] = -alpha*R*cos(ot); |
| 31 |
bigPosition[1] = -alpha*R*sin(ot); |
| 32 |
bigPosition[2] = 0; |
| 33 |
smallPosition[0] = (1-alpha)*R*cos(ot); |
| 34 |
smallPosition[1] = (1-alpha)*R*sin(ot); |
| 35 |
smallPosition[2] = 0; |
| 36 |
float otr = OMEGA*R; |
| 37 |
velocity[0] = otr*sin(ot); |
| 38 |
velocity[1] = otr*cos(ot); |
| 39 |
velocity[2]=0; |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
//////////////////////////////////////////////////////////////////////////////////// |
| 44 |
// |
| 45 |
void |
| 46 |
smallPrimaryMovingOrbit(float R, float T, float t, |
| 47 |
float position[], float velocity[]) |
| 48 |
// |
| 49 |
//////////////////////////////////////////////////////////////////////////////////// |
| 50 |
{ |
| 51 |
float OMEGA = 2.0*M_PI; |
| 52 |
float ot = OMEGA*t; |
| 53 |
|
| 54 |
position[0] = R*cos(ot); |
| 55 |
position[1] = R*sin(ot); |
| 56 |
position[2] = 0; |
| 57 |
float otr = OMEGA*R; |
| 58 |
velocity[0] = otr*sin(ot); |
| 59 |
velocity[1] = otr*cos(ot); |
| 60 |
velocity[2]=0; |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
/////////////////////////////////////////////////////////////////////////////// |
| 65 |
// |
| 66 |
// given the center, xyzCoords, velocity, time, mass ratio and T, R,g |
| 67 |
// calculate the inertial frame position. |
| 68 |
// |
| 69 |
/////////////////////////////////////////////////////////////////////////////// |
| 70 |
|
| 71 |
void satelliteMovingOrbit(int center, float xyzCoords[], |
| 72 |
float time, float mu, float R, float TS, float T, float g, |
| 73 |
float *rpf, float *vpf ) |
| 74 |
{ |
| 75 |
float OMEGA = 2.0*M_PI; |
| 76 |
time = time*TS; |
| 77 |
float ot = time*OMEGA; |
| 78 |
|
| 79 |
float havv[3]; |
| 80 |
float HavOmr = OMEGA*R*R; |
| 81 |
havv[0] = 0; |
| 82 |
havv[1] = 0; |
| 83 |
havv[2] = HavOmr; |
| 84 |
|
| 85 |
float ex[3], ey[3], ez[3]; |
| 86 |
ex[0] = cos(ot); ex[1]=sin(ot); ex[2]= 0; |
| 87 |
ey[0] =-sin(ot); ey[1]=cos(ot); ey[2]= 0; |
| 88 |
ez[0] = 0 ; ez[1]=0; ez[2]= 1; |
| 89 |
|
| 90 |
float ptmp[3]; |
| 91 |
float c = -mu; |
| 92 |
|
| 93 |
if(center == 1) c = 0; |
| 94 |
else if(center == 2) c = -mu; |
| 95 |
else c = 1-mu; |
| 96 |
|
| 97 |
for(int i=0; i<3; i++) |
| 98 |
{ |
| 99 |
ptmp[i] = (xyzCoords[0]-c)*ex[i] + xyzCoords[1]*ey[i]+ xyzCoords[2]*ez[i]; |
| 100 |
rpf[i]= R*ptmp[i]; |
| 101 |
} |
| 102 |
} |