ggAstro Astronautics

ggame extensions for modeling spacecraft in planetary orbit

Rocket

class ggame.astro.Rocket(planet, **kwargs)[source]

Rocket is a class for simulating the motion of a projectile through space, acted upon by arbitrary forces (thrust) and by gravitaitonal attraction to a single planetary object.

Initialize the Rocket object.

Example:

rocket1 = Rocket(earth, altitude=400000, velocity=7670, timezoom=2)

Required parameters:

  • planet: Reference to a Planet object.

Optional keyword parameters are supported:

  • bitmap: url of a suitable bitmap image for the rocket (png recommended) default is ggimages/rocket.png
  • bitmapscale: scale factor for bitmap. Default is 0.1
  • velocity: initial rocket speed. default is zero.
  • directiond: initial rocket direction in degrees. Default is zero.
  • direction: initial rocket direction in radians. Default is zero.
  • tanomalyd: initial rocket true anomaly in degrees. Default is 90.
  • tanomaly: initial rocket true anomaly in radians. Default is pi/2.
  • altitude: initial rocket altitude in meters. Default is zero.
  • showstatus: boolean displays flight parameters on screen. Default is True.
  • statuspos: tuple with x,y coordinates of flight parameters. Default is upper left.
  • statuslist: list of status names to include in flight parameters. Default is all, consisting of: “velocity”, “acceleration”, “course”, “altitude”, “thrust”, “mass”, “trueanomaly”, “scale”, “timezoom”, “shiptime”
  • leftkey: a ggame key identifier that will serve as the “rotate left” key while controlling the ship. Default is ‘left arrow’.
  • rightkey: a ggame key identifier that will serve as the “rotate right” key while controlling the ship. Default is ‘right arrow’.

Following parameters may be set as a constant value, or pass in the name of a function that will return the value dynamically or the name of a ggmath UI control that will return the value.

  • timezoom scale factor for time zoom. Factor = 10^timezoom
  • heading direction to point the rocket in (must be radians)
  • mass mass of the rocket (must be kg)
  • thrust thrust of the rocket (must be N)

Animation related parameters may be ignored if no sprite animation:

  • bitmapframe ((x1,y1),(x2,y2)) tuple defines a region in the bitmap
  • bitmapqty number of bitmaps – used for animation effects
  • bitmapdir “horizontal” or “vertical” use with animation effects
  • bitmapmargin pixels between successive animation frames
  • tickrate frequency of spacecraft dynamics calculations (Hz)
getthrust()[source]

User override function for dynamically determining thrust force.

getmass()[source]

User override function for dynamically determining rocket mass.

getheading()[source]

User override function for dynamically determining the heading.

gettimezoom()[source]

User override function for dynamically determining the timezoom.

addStatusReport(statuslist, statusfuncs, statusselect)[source]

Accept list of all status names, all status text functions, and the list of status names that have been selected for display.

velocityText()[source]

Report the velocity in m/s as a text string.

accelerationText()[source]

Report the acceleration in m/s as a text string.

courseDegreesText()[source]

Report the heading in degrees (zero to the right) as a text string.

thrustText()[source]

Report the thrust level in Newtons as a text string.

massText()[source]

Report the spacecraft mass in kilograms as a text string.

trueAnomalyDegreesText()[source]

Report the true anomaly in degrees as a text string.

trueAnomalyRadiansText()[source]

Report the true anomaly in radians as a text string.

altitudeText()[source]

Report the altitude in meters as a text string.

radiusText()[source]

Report the radius (distance to planet center) in meters as a text string.

scaleText()[source]

Report the view scale (pixels/meter) as a text string.

timeZoomText()[source]

Report the time acceleration as a text string.

shipTimeText()[source]

Report the elapsed time as a text string.

dynamics(timer)[source]

Perform one iteration of the simulation using runge-kutta 4th order method.

fr(pos)[source]

Compute the net force vector on the rocket, as a function of the position vector.

ar(pos)[source]

Compute the acceleration vector of the rocket, as a function of the position vector.

vadd(v1, v2)[source]

Vector add utility.

vmul(s, v)[source]

Scalar vector multiplication utility.

vmag(v)[source]

Vector magnitude function.

fgrav()[source]

Vector force due to gravity, at current position.

turn(event)[source]

Respond to left/right turning key events.

Planet

class ggame.astro.Planet(**kwargs)[source]

Initialize the Planet object.

Optional keyword parameters are supported:

  • viewscale pixels per meter in graphics display. Default is 10.
  • radius radius of the planet in meters. Default is Earth radius.
  • planetmass mass of the planet in kg. Default is Earth mass.
  • color color of the planet. Default is greenish (0x008040).
  • viewalt altitude of initial viewpoint in meters. Default is rocket altitude.
  • viewanom true anomaly (angle) of initial viewpoint in radians. Default is the rocket anomaly.
  • viewanomd true anomaly (angle) of initial viewpoing in degrees. Default is the rocket anomaly.
run(rocket=None)[source]

Execute the Planet (and Rocket) simulation.

Optional parameters:

  • rocket Reference to a Rocket object - sets the initial view