Hello.
I'm currently in a bit of a bind, as I want to develop a little Java tool to visualize the trajectory of a body around its parent body, using Keplers Laws and the Keplerian Orbital Elements. In a quest to learn Java3D.
May or may not be related to the KSP calculator
Having moved from a simple 2D plane into 3D is harder then I thought.
To integrate inclination was relatively easy, but now I am stuck with integrating the other three orbital elements
Now I am hoping that you can help me out here as I already tried to find something via Google and Wikipedia as well as going through any page on Orbital Mechanics and programming I have found.
I think I'll just add the code as well...
Please note that dist_cor and per_cor are correction factors for scaling distances and orbital periods of the orbits.
I think that I may have nailed the Longitude of the ascending node by starting to calculate the orbit with starting at:
I'm currently in a bit of a bind, as I want to develop a little Java tool to visualize the trajectory of a body around its parent body, using Keplers Laws and the Keplerian Orbital Elements. In a quest to learn Java3D.
May or may not be related to the KSP calculator
Having moved from a simple 2D plane into 3D is harder then I thought.
To integrate inclination was relatively easy, but now I am stuck with integrating the other three orbital elements
- Longitude of the ascending node
- Argument of periapsis
- Mean anomaly
Now I am hoping that you can help me out here as I already tried to find something via Google and Wikipedia as well as going through any page on Orbital Mechanics and programming I have found.
I think I'll just add the code as well...
Code:
/**
* Keplerian Orbital Elements
*/
protected double eccentricity; // Eccentricity e
protected double semimajor_axis; // Semimajor Axis a
protected double inclination; // Inclination i
protected double asc_node; // Longitude of the ascending node
protected double per_arg; // Argument of periapsis
protected double mean_anomaly; // Mean Anomaly
/**
* Kepler Ellpise Calculaton Elements
*/
protected double kep_radius;
protected double kep_delta_angle;
protected double kep_angle_moved = 0;
protected double kep_delta_time = 0.1;
/**
* Calculates the Radius and the angle of a Kepler ellipse moved during a delta t
*/
public void keplerMovedAngle() {
// Calculate Radius
kep_radius = (1 - eccentricity * eccentricity) / (1 - eccentricity * Math.cos(deg2rad(kep_angle_moved)));
// Calculate angle delta
kep_delta_angle = 2 * Math.PI * Math.sqrt(1 - eccentricity * eccentricity) / (kep_radius * kep_radius) * (kep_delta_time * per_cor);
kep_angle_moved += kep_delta_angle;
}
/**
* Calculates the position of an object in the Kepler ellipse at a specific time
*
* @return Position Vector of orbiting object
*/
public Vector3d keplerPosition() {
// Add deltas
double rad = deg2rad(kep_angle_moved);
double inc = deg2rad(inclination);
// Calculate Coordinates
double pz = dist_cor * kep_radius * Math.cos(rad);
double px = dist_cor * kep_radius * Math.sin(rad) * Math.cos(inc);
double py = dist_cor * kep_radius * Math.sin(rad) * Math.sin(inc);
Vector3d keplerVector = new Vector3d(px, py, pz);
return keplerVector;
}
Please note that dist_cor and per_cor are correction factors for scaling distances and orbital periods of the orbits.
I think that I may have nailed the Longitude of the ascending node by starting to calculate the orbit with starting at:
Code:
kep_angle_moved = -asc_node