source: proiecte/SolarSim/Matlab/keplerToCarthezian.m @ 152

Last change on this file since 152 was 152, checked in by (none), 14 years ago
File size: 1.3 KB
Line 
1function [R,V,v] = keplerToCarthezian(I,Omega,w,a,ecc,M,tol)
2
3    if nargin < 6 || nargin > 7
4        error('Incorrect number of inputs')
5    elseif nargin == 6
6        tol = 10^-8;
7    end
8   
9    mu_sun = 132712440018; %km^3/s^2
10
11    E = CalcEA(M,ecc);
12    nu = nuFromM(M,ecc,tol);
13    r = a * (1 - ecc*ecc)/(1+ecc*cos(nu));
14    p = a * (1 - ecc*ecc);
15   
16    rx = r * (cos(Omega)*cos(w+nu) - sin(Omega)*cos(I)*sin(w+nu));
17    ry = r * (sin(Omega)*cos(w+nu) + cos(Omega)*cos(I)*sin(w+nu));
18    rz = r * sin(I) * sin(w+nu);
19
20    v = sqrt( mu_sun * (2/r - 1/a) );
21   
22%    vx = -sqrt(mu_sun/p) * (cos(Omega)*(sin(w+nu)+ecc*sin(w))-sin(Omega)*cos(I)*(cos(w+nu)+ecc*cos(w)));
23%    vy = -sqrt(mu_sun/p) * (sin(Omega)*(sin(w+nu)+ecc*sin(w))-cos(Omega)*cos(I)*(cos(w+nu)+ecc*cos(w)));
24%    vz =  sqrt(mu_sun/p) * sin(I)*(cos(w+nu)+ecc*cos(w));
25
26    if (I > 0)
27        A = [ sin(I)*sin(Omega) -sin(I)*cos(Omega) ; rx ry ];
28        B = [ -cos(I) ; -rz ];
29        rez = inv(A) * B;
30        a = rez(1);
31        b = rez(2);
32
33        vz = v / sqrt(1 + a*a + b*b);
34        vx = a * vz;
35        vy = b * vz;
36    else
37        vx = v / sqrt(1+(rx*rx)/(ry*ry));
38        vy = - rx/ry * vx;
39        vz = 0;
40    end
41   
42    R = [rx ry rz];
43    V = [vx vy vz];
44   
45end
46   
Note: See TracBrowser for help on using the repository browser.