Orbital elements: Difference between revisions
m
syntax highlighting fixup automation
m (→{{header|J}}) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 35:
{{trans|Python}}
<
R v1 * x1 + v2 * x2
Line 69:
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])</
{{out}}
Line 79:
=={{header|Ada}}==
{{Trans|Kotlin}}
<
with Ada.Numerics.Generic_Real_Arrays;
with Ada.Numerics.Generic_Elementary_Functions;
Line 184:
Put ("Position : "); Put (State.Position); New_Line;
Put ("Speed : "); Put (State.Speed); New_Line;
end Orbit;</
{{out}}
<pre>
Line 193:
=={{header|ALGOL W}}==
{{Trans|C}} (which is a translation of Kotlin which is a translation of ...).
<
% compute orbital elements %
% 3-element vector %
Line 277:
write( "Speed : " ); writeOnVector( speed )
end
end.</
{{out}}
<pre>
Line 285:
=={{header|C}}==
{{trans|Kotlin}}
<
#include <math.h>
Line 360:
printf("Speed : %s\n", buffer);
return 0;
}</
{{output}}
Line 370:
=={{header|C sharp|C#}}==
{{trans|D}}
<
namespace OrbitalElements {
Line 455:
}
}
}</
{{out}}
<pre>Position : (0.77942284339868, 0.450000034653684, 0)
Line 462:
=={{header|C++}}==
{{trans|C#}}
<
#include <tuple>
Line 558:
return 0;
}</
{{out}}
<pre>Position : (0.779423, 0.45, 0)
Line 565:
=={{header|D}}==
{{trans|Kotlin}}
<
import std.stdio;
import std.typecons;
Line 653:
writeln("Position : ", res[0]);
writeln("Speed : ", res[1]);
}</
{{out}}
<pre>Position : (0.7794228433986798, 0.4500000346536842, 0.0000000000000000)
Line 660:
=={{header|Go}}==
{{trans|Kotlin}}
<
import (
Line 731:
fmt.Println("Position :", position)
fmt.Println("Speed :", speed)
}</
{{out}}
Line 740:
=={{header|J}}==
{{trans|Raku}}<
NB. x: axis (0, 1 or 2), y: angle in radians
R=: {{ ((2 1,:1 2) o.(,-)y*_1^2|x)(,&.>/~0 1 2-.x)} =i.3 }}
Line 761:
speed=. (%:(2%ra)-%a)*norm(rp,ra,0) X ijk
position,:speed
}}</
The true anomaly, argument of Periapsis, Longitude of the ascending node and inclination are all angles. And we use the dot product of their rotation matrices (in that order) to find the orientation of the orbit and the object's position in that orbit. Here, <code>R</code> finds the rotation matrix for a given angle around a given axis. Here's an example of what R gives us for a sixty degree angle:
<
┌────────────────────┬────────────────────┬────────────────────┐
│1 0 0│ 0.5 0 _0.866025│ 0.5 0.866025 0│
│0 0.5 0.866025│ 0 1 0│_0.866025 0.5 0│
│0 _0.866025 0.5│0.866025 0 0.5│ 0 0 1│
└────────────────────┴────────────────────┴────────────────────┘</
Task example:<
0.779423 0.45 0
_0.552771 0.957427 0</
=={{header|Java}}==
{{trans|Kotlin}}
<
private static class Vector {
private double x, y, z;
Line 858:
System.out.printf("Speed : %s\n", ps[1]);
}
}</
{{out}}
Line 868:
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
<
def addVectors: transpose | map(add);
Line 904:
| divide(abs)
| multiply( ((2 / $r) - (1 / semimajorAxis))|sqrt) as $speed
| [$position, $speed] ;</
'''The Task'''
<
| "Position : \(.[0])",
"Speed : \(.[1])"</
{{out}}
<pre>
Line 917:
=={{header|Julia}}==
{{trans|Kotlin}}
<
import Base.abs, Base.print
Line 952:
testorbitalmath()
</
<pre>
Position : (0.7794228433986797, 0.45000003465368416, 0.0)
Line 960:
=={{header|Kotlin}}==
{{trans|Sidef}}
<
class Vector(val x: Double, val y: Double, val z: Double) {
Line 1,023:
println("Position : $position")
println("Speed : $speed")
}</
{{out}}
<pre>Position : (0.7794228433986797, 0.45000003465368416, 0.0)
Line 1,030:
=={{header|Nim}}==
{{trans|Kotlin}}
<
type Vector = tuple[x, y, z: float]
Line 1,086:
trueAnomaly = 0.0)
echo "Position: ", position
echo "Speed: ", speed</
{{out}}
Line 1,094:
=={{header|ooRexx}}==
{{trans|Java}}
<
Numeric Digits 16
ps = orbitalStateVectors(1.0, 0.1, 0.0, 355.0 / (113.0 * 6.0), 0.0, 0.0)
Line 1,200:
Return res
::requires 'rxmath' LIBRARY</
{{out}}
Line 1,211:
=={{header|Perl}}==
{{trans|Raku}}
<
use warnings;
use Math::Vector::Real;
Line 1,270:
0, # argument of periapsis
0 # true-anomaly
;</
{{out}}
<pre>$VAR1 = {
Line 1,287:
=={{header|Phix}}==
{{trans|Python}}
<!--<
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">vabs</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">v</span><span style="color: #0000FF;">)</span>
Line 1,327:
<span style="color: #000000;">orbitalStateVectors</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1.0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">355.0</span> <span style="color: #0000FF;">/</span> <span style="color: #0000FF;">(</span><span style="color: #000000;">113.0</span> <span style="color: #0000FF;">*</span> <span style="color: #000000;">6.0</span><span style="color: #0000FF;">),</span> <span style="color: #000000;">0.0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">0.0</span><span style="color: #0000FF;">)</span>
<!--</
{{out}}
<pre>
Line 1,339:
This implementation uses the CLP/R library of swi-prolog, but doesn't have to. This removes the need for a vector divide and has limited capability to reverse the functionality (eg: given the position/speed find some orbital elements).
<
v3_add(v(X1,Y1,Z1),v(X2,Y2,Z2),v(X,Y,Z)) :-
Line 1,397:
find_l(Ecc, SemiMajor, L) :-
dif(Ecc,1.0),
{ L = SemiMajor * (1.0 - Ecc * Ecc) }.</
{{out}}
<pre>
Line 1,408:
=={{header|Python}}==
<
class Vector:
Line 1,466:
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]</
{{out}}
<pre>Position : (0.787295801413, 0.454545489549, 0.0)
Line 1,474:
(formerly Perl 6)
We'll use the [https://github.com/grondilu/clifford Clifford geometric algebra library] but only for the vector operations.
<syntaxhighlight lang="raku"
Real :$semimajor-axis where * >= 0,
Real :$eccentricity where * >= 0,
Line 1,517:
longitude-of-ascending-node => pi/6,
argument-of-periapsis => pi/4,
true-anomaly => 0;</
{{out}}
<pre>{position => 0.237771283982207*e0+0.860960261697716*e1+0.110509023572076*e2, speed => -1.06193301748006*e0+0.27585002056925*e1+0.135747024865598*e2}</pre>
Line 1,525:
{{trans|Java}}
Vectors are represented by strings: 'x/y/z'
<
Numeric Digits 16
Parse Value orbitalStateVectors(1.0,0.1,0.0,355.0/(113.0*6.0),0.0,0.0),
Line 1,660:
End
Numeric Digits prec
Return r+0</
{{out}}
<pre>Position : (0.7794228433986798,0.4500000346536842,0)
Line 1,667:
===version 2===
Re-coding of REXX version 1, but with greater decimal digits precision.
<
numeric digits length( pi() ) - length(.) /*limited to pi len, but show 1/3 digs.*/
call orbV 1, .1, 0, 355/113/6, 0, 0 /*orbital elements taken from: Java */
Line 1,718:
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</
{{out|output|text= when using the default internal inputs:}}
<pre>
Line 1,743:
=={{header|Scala}}==
<
object OrbitalElements extends App {
Line 1,785:
}
}</
{{Out}}Best seen running in your browser either by [https://scalafiddle.io/sf/ac17jh2/0 ScalaFiddle (ES aka JavaScript, non JVM)] or [https://scastie.scala-lang.org/2NQNgj4OQkazxZNvSzcexQ Scastie (remote JVM)].
=={{header|Sidef}}==
{{trans|Perl}}
<
semimajor_axis,
eccentricity,
Line 1,846:
say "Position : #{r.position}"
say "Speed : #{r.speed}\n"
}</
{{out}}
<pre>
Line 1,862:
{{trans|Kotlin}}
<
public struct Vector {
Line 1,964:
)
print("Position: \(position); Speed: \(speed)")</
{{out}}
Line 1,972:
=={{header|Wren}}==
{{trans|Kotlin}}
<
construct new(x, y, z) {
_x = x
Line 2,030:
var ps = orbitalStateVectors.call(1, 0.1, 0, 355 / (113 * 6), 0, 0)
System.print("Position : %(ps[0])")
System.print("Speed : %(ps[1])")</
{{out}}
Line 2,040:
=={{header|zkl}}==
{{trans|Perl}}
<
longitude_of_ascending_node, argument_of_periapsis, true_anomaly){
i,j,k:=T(1.0, 0.0, 0.0), T(0.0, 1.0, 0.0), T(0.0, 0.0, 1.0);
Line 2,069:
return(position,speed);
}</
<
1.0, # semimajor axis
0.1, # eccentricity
Line 2,077:
0.0, # argument of periapsis
0.0 # true-anomaly
).println();</
{{out}}
<pre>L(L(0.779423,0.45,0),L(-0.552771,0.957427,0))</pre>
|