Orbital elements: Difference between revisions

Content added Content deleted
(→‎{{header|jq}}: simplify)
(Added 11l)
Line 31: Line 31:
TODO: pick an example from a reputable source, and bring the algorithm description onto this site. (Restating those pages in concise a fashion comprehensible to the coders and readers of this site will be a good exercise.)
TODO: pick an example from a reputable source, and bring the algorithm description onto this site. (Restating those pages in concise a fashion comprehensible to the coders and readers of this site will be a good exercise.)
<br><br>
<br><br>

=={{header|11l}}==
{{trans|Python}}

<lang 11l>F mulAdd(v1, x1, v2, x2)
R v1 * x1 + v2 * x2

F rotate(i, j, alpha)
R [mulAdd(i, cos(alpha), j, sin(alpha)), mulAdd(i, -sin(alpha), j, cos(alpha))]

F orbitalStateVectors(semimajorAxis, eccentricity, inclination, longitudeOfAscendingNode, argumentOfPeriapsis, trueAnomaly)
V i = (1.0, 0.0, 0.0)
V j = (0.0, 1.0, 0.0)
V k = (0.0, 0.0, 1.0)

V p = rotate(i, j, longitudeOfAscendingNode)
i = p[0]
j = p[1]
p = rotate(j, k, inclination)
j = p[0]
p = rotate(i, j, argumentOfPeriapsis)
i = p[0]
j = p[1]

V l = I (eccentricity == 1.0) {2.0} E 1.0 - eccentricity * eccentricity
l *= semimajorAxis
V c = cos(trueAnomaly)
V s = sin(trueAnomaly)
V r = 1 / (1.0 + eccentricity * c)
V rprime = s * r * r / l
V position = mulAdd(i, c, j, s) * r
V speed = mulAdd(i, rprime * c - r * s, j, rprime * s + r * c)
speed = normalize(speed) * sqrt(2.0 / r - 1.0 / semimajorAxis)

R [position, speed]

V ps = orbitalStateVectors(1.0, 0.1, 0.0, 355.0 / (113.0 * 6.0), 0.0, 0.0)
print(‘Position : ’ps[0])
print(‘Speed : ’ps[1])</lang>

{{out}}
<pre>
Position : (0.787295801, 0.45454549, 0)
Speed : (-0.5477226, 0.948683274, 0)
</pre>


=={{header|ALGOL W}}==
=={{header|ALGOL W}}==