API Question Random Orbit Method

sfpilot

New member
Joined
Mar 11, 2009
Messages
24
Reaction score
0
Points
0
I need to make a method(or function i don't know which they are called in C++) that generates a random orbit around the inputted body. before i do so though i wanted to make sure i am not reinventing the wheel. if anyone has ever made this type of method before i would appreciate it if i could use it in my addon. with credit to the developer of the method. i am mostly hoping that someone else has made it because even though i probably could figure it out after a very long time, if someone else has already gone through the trouble to do such a thing why make a second one?
 
Check out OCALC

Have a look at my OCALC program...with just a reference body mass, and the periapsis & apoapsis distances you can calculate orbital details quite easily. Just use random altitudes (as long as peri <= apo, and above the surface/atmosphere) and you've got your orbit! If it looks ok I can give you all the required calculations.

Trevor
 
that looks like exactly the kind of calculations i was looking for. Thank you Very much for helping me with this. it looks like if i could use these calculations in a method then it would make my addon a lot more versatile since it could work with absolutely any gravitational body. and judging by the variables it would output, it could all be stored in an ORBITPARAM structure.
 
Here's some calculations

Just pulled this straight out of the source code...shouldn't be too hard to work out.

Note: just watch your units...I'm using km for altitudes

Code:
  { calculate Periapsis & Apoapsis }
  PeriRad.Value := rRadius.Value + PeriAlt.Value;
  ApoRad.Value := rRadius.Value + ApoAlt.Value;
  { calculate semi-major axis }
  SemiMajor.Value := (PeriRad.Value + ApoRad.Value) / 2.0;
  { eccentricity }
  Eccen.Value := (ApoRad.Value - PeriRad.Value) / (ApoRad.Value + PeriRad.Value);
  { mechanical energy }
  mu := 6.67259E3 * rMass.Value;
  Energy.Value := -mu / (2.0 * SemiMajor.Value);
  { period }
  secs := 2.0 * pi * sqrt(SemiMajor.Value * SemiMajor.Value * SemiMajor.Value / mu);
  Period.Value := secs;
  mins := trunc(secs / 60);
  secs := secs - (mins * 60);
  hours := trunc(mins / 60);
  mins := mins - (hours * 60);
  days := trunc(hours / 24);
  hours := hours - (days * 24);
  edtPeriod.Text := '';
  if (days > 0) then
    edtPeriod.Text := Format('%d d ', [days]);
  edtPeriod.Text := edtPeriod.Text + Format('%2.2d:%2.2d:', [hours, mins]);
  edtPeriod.Text := edtPeriod.Text + formatfloat('00.000', secs);
  { P }
  p.value := SemiMajor.Value * (1.0 - Eccen.Value * Eccen.Value);
  { H }
  h.value := sqrt(p.value * mu);
  { periapsis velocity }
  PeriVel.Value := h.value / PeriRad.Value;
  { apoapsis velocity }
  ApoVel.Value := h.value / ApoRad.Value;
 
Back
Top