Orbital elements: Difference between revisions

Content added Content deleted
m (→‎version 2: simplified the REXX code by eliding the need to use a slash separator for vectors, other improvements.)
m (→‎version 2: moved subroutines/functions, added whitespace.)
Line 940: Line 940:
<lang rexx>/*REXX pgm converts orbital elements ──► orbital state vectors (angles are in radians).*/
<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.*/
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
parse value orbV(1, .1, 0, 355/(113*6), 0, 0) with position '~' speed
say ' position:' show(position)
say ' position:' show(position)
say ' speed:' show(speed)
say ' speed:' show(speed)
exit /*stick a fork in it, we're all done. */
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
orbV: procedure; parse arg semiMaj, eccentricity, inclination, node, periapsis, anomaly
Line 967: Line 958:
return mulV( MA(i,c,j,s), r)'~'mulV( divV( speed, absV(speed)),sqrt(2/r -1/semiMaj))
return mulV( MA(i,c,j,s), r)'~'mulV( divV( speed, absV(speed)),sqrt(2/r -1/semiMaj))
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
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
MA: procedure; parse arg x y z,a,xx yy zz,b; return (x*a+xx*b) (y*a+yy*b) (z*a+zz*b)
MA: procedure; parse arg x y z,a,xx yy zz,b; return (x*a+xx*b) (y*a+yy*b) (z*a+zz*b)
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*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
cos: procedure; parse arg x; x= r2r(x); a=abs(x); hpi= pi * .5
cos: procedure; parse arg x; x= r2r(x); a=abs(x); hpi= pi * .5