Orbital elements: Difference between revisions
Content added Content deleted
Walterpachl (talk | contribs) m (fix tag) |
(→{{header|REXX}}: added REXX version 2.) |
||
Line 792: | Line 792: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
===version 1=== |
|||
{{trans|Java}} |
{{trans|Java}} |
||
Vectors are represented by strings: 'x/y/z' |
Vectors are represented by strings: 'x/y/z' |
||
Line 933: | Line 934: | ||
<pre>Position : (0.7794228433986798,0.4500000346536842,0) |
<pre>Position : (0.7794228433986798,0.4500000346536842,0) |
||
Speed : (-0.5527708425678772,0.9574270859639177,0)</pre> |
Speed : (-0.5527708425678772,0.9574270859639177,0)</pre> |
||
===version 2=== |
|||
{{trans|REXX}} |
|||
Translation of REXX version 1. |
|||
<lang rexx>/*REXX pgm converts orbital elements ──► orbital state vectors (angles are in radians).*/ |
|||
numeric digits length(pi() ) - 1 /*limited to pi len, but show 1/3 digs.*/ |
|||
parse value orbV(1, 0.1, 0, 355 / (113*6), 0, 0) with position speed |
|||
say ' position:' show(position) |
|||
say ' speed:' show(speed) |
|||
exit /*stick a fork in it, we're all done. */ |
|||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
|||
absV: procedure; parse arg x '/' y "/" z; return sqrt(x**2 + y**2 + z**2) |
|||
divV: procedure; parse arg x '/' y "/" z,d; return (x/d)'/' || (y/d)'/' || (z/d) |
|||
mulV: procedure; parse arg x '/' y "/" z,d; return (x*d)'/' || (y*d)'/' || (z*d) |
|||
show: procedure; parse arg a '/' b '/' c; return '('fmt(a)"," fmt(b)',' fmt(c)")" |
|||
fmt: procedure; parse arg #; return left('', #>=0)format(#,,digits()%3)/1 |
|||
pi: pi=3.1415926535897932384626433832795028841971693993751058209749445923; return pi |
|||
rot: procedure; parse arg i,j,$; return MA(i, cos($),j,sin($)) MA(i, -sin($), j, cos($)) |
|||
r2r: return arg(1) // (pi() *2) /*normalize radians ──► a unit circle*/ |
|||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
|||
orbV: procedure; parse arg semiMaj, eccentricity, inclination, node, periapsis, anomaly |
|||
parse value '1/0/0 0/1/0 0/0/1' with i j k |
|||
parse value rot(i, j, node) with i j /*rotate ascending node longitude.*/ |
|||
j= word(rot(j, k, inclination), 1) /*rotate the inclination. */ |
|||
parse value rot(i, j, periapsis) with i j /*rotate the argument of periapsis*/ |
|||
if eccentricity=1 then L= 2 |
|||
else L= 1 - eccentricity**2 |
|||
L= L * semiMaj /*calculate the semi─latus rectum.*/ |
|||
c= cos(anomaly); s= sin(anomaly) /*calculate COS and SIN of anomoly*/ |
|||
r= L / (1 + eccentricity * c) |
|||
@= s*r**2 / L; speed= MA(i, @*c - r*s, j, @*s + r*c) |
|||
return mulV(MA(i, c, j, s), r) mulV(divV(speed, absV(speed)), sqrt(2/r -1/semiMaj)) |
|||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
|||
MA: procedure; parse arg x '/' y "/" z, a, xx '/' yy "/" zz, b; slash= '/' |
|||
return (x*a + xx*b)slash || (y*a + yy*b)slash || (z*a + zz*b) |
|||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
|||
cos: procedure; parse arg x; x= r2r(x); a=abs(x); hpi= pi * .5 |
|||
numeric fuzz min(6, digits() - 3); if a=pi() then return -1 |
|||
if a=hpi | a=hpi*3 then return 0; if a=pi() / 3 then return .5 |
|||
if a=pi() * 2 / 3 then return -.5; return .sinCos(1, -1) |
|||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
|||
sin: procedure; parse arg x; x=r2r(x); numeric fuzz min(5, max(1, digits() -3)) |
|||
if x=pi * .5 then return 1; if x==pi * 1.5 then return -1 |
|||
if abs(x)=pi | x=0 then return 0; return .sinCos(x, 1) |
|||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
|||
.sinCos: parse arg z 1 _,i; xx= x*x |
|||
do k=2 by 2 until p=z; p=z; _= -_ * xx / (k*(k+i)); z= z+_; end; return z |
|||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
|||
sqrt: procedure; parse arg x; if x=0 then return 0; d=digits(); numeric form; m.=9; h=d+6 |
|||
numeric digits; parse value format(x,2,1,,0) 'E0' with g 'E' _ .; g= g *.5'e'_ % 2 |
|||
do j=0 while h>9; m.j=h; h= h % 2 + 1; end |
|||
do k=j+5 to 0 by -1; numeric digits m.k; g= (g+x/g) * .5; end; return g</lang> |
|||
{{out|output|text= when using the default internal inputs:}} |
|||
<pre> |
|||
position: ( 0.779422843398679832042, 0.450000034653684237432, 0) |
|||
speed: (-0.552770840960443759673, 0.957427083179761535246, 0) |
|||
</pre> |
|||
=={{header|Scala}}== |
=={{header|Scala}}== |