Orbital elements: Difference between revisions
Content added Content deleted
Line 667: | Line 667: | ||
<pre>Position : (0.7794228433986797, 0.4500000346536842, 0.0000000000000000) |
<pre>Position : (0.7794228433986797, 0.4500000346536842, 0.0000000000000000) |
||
Speed : (-0.5527708409604438, 0.9574270831797618, 0.0000000000000000)</pre> |
Speed : (-0.5527708409604438, 0.9574270831797618, 0.0000000000000000)</pre> |
||
=={{header|jq}}== |
|||
{{trans|Wren}} |
|||
{{works with|jq}} |
|||
'''Works with gojq, the Go implementation of jq''' |
|||
<lang jq># Array/vector operations |
|||
def addVectors: transpose | map(add); |
|||
def multiply($m): map(. * $m); |
|||
def divide($d): map(1/$d); |
|||
def abs: map(.*.) | add | sqrt; |
|||
def orbitalStateVectors(semimajorAxis; eccentricity; inclination; |
|||
longitudeOfAscendingNode; argumentOfPeriapsis; trueAnomaly): |
|||
def mulAdd($v1; $x1; $v2; $x2): |
|||
[($v1|multiply($x1)), ($v2|multiply($x2))] | addVectors; |
|||
def rotate($i; $j; $alpha): |
|||
[mulAdd($i; $alpha|cos; $j; $alpha|sin), |
|||
mulAdd($i; -$alpha|sin; $j; $alpha|cos)]; |
|||
[1, 0, 0] as $i |
|||
| [0, 1, 0] as $j |
|||
| [0, 0, 1] as $k |
|||
| rotate($i; $j; longitudeOfAscendingNode) as [$i, $j] |
|||
| rotate($j; $k; inclination) as [$j, $_] |
|||
| rotate($i; $j; argumentOfPeriapsis) as [$i, $j] |
|||
| (semimajorAxis * (if (eccentricity == 1) then 2 else (1 - eccentricity * eccentricity) end)) as $l |
|||
| (trueAnomaly|cos) as $c |
|||
| (trueAnomaly|sin) as $s |
|||
| ($l / (1 + eccentricity * $c)) as $r |
|||
| ($s * $r * $r / $l) as $rprime |
|||
| mulAdd($i; $c; $j; $s) | multiply($r) as $position |
|||
| mulAdd($i; $rprime * $c - $r * $s; $j; $rprime * $s + $r * $c) as $speed |
|||
| ($speed | divide($speed|abs)) as $speed |
|||
| ($speed | multiply( ((2 / $r) - (1 / semimajorAxis))|sqrt)) as $speed |
|||
| [$position, $speed] ;</lang> |
|||
'''The Task''' |
|||
<lang jq>orbitalStateVectors(1; 0.1; 0; 355 / (113 * 6); 0; 0) |
|||
| "Position : \(.[0])", |
|||
"Speed : \(.[1])"</lang> |
|||
{{out}} |
|||
<pre> |
|||
Position : [0.7794228433986797,0.45000003465368416,0] |
|||
Speed : [1.228379551983482,1.228379551983482,1.228379551983482] |
|||
</pre> |
|||
=={{header|Julia}}== |
=={{header|Julia}}== |