Orbital elements: Difference between revisions

m
→‎version 2: simplified the REXX code by eliding the need to use a slash separator for vectors, other improvements.
(→‎{{header|REXX}}: added REXX version 2.)
m (→‎version 2: simplified the REXX code by eliding the need to use a slash separator for vectors, other improvements.)
Line 940:
<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
parsei= value '1/ 0/ 0; 0/1/0 j= 0/0/ 1' 0; with i j k= 0 0 1
parse value rot(i, j, node) with i '~' withj i j /*rotate ascending node longitude.*/
j=parse value word(rot(j, k, inclination), 1) with j '~' /*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
Line 965:
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; return (x*a+xx*b) (y*a+yy*b) slash= '/'(z*a+zz*b)
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