Using __repr__ or __str__ for own printable class?

Erik Max Francis max at alcyone.com
Tue Apr 15 02:26:24 CEST 2003


Irmen de Jong wrote:

> Erik Max Francis wrote:
> 
> >>>>Course(lowEarthOrbit, lowMarsOrbit).transfers()
> >
> > [<ExtractionTransfer @ 0x82893ac (out of `low orbit around
> > `Earth'')>,
> > <HohmannTransfer @ 0x812cef4 (Hohmann from `Earth' to `Mars')>,
> > <InsertionTransfer @ 0x82adb64 (into `low orbit around `Mars'')>]
> 
> Is this actual code? What does this do? I'm interested.

One of my side projects is a computer roleplaying game set in a real
Solar System with realistic orbital mechanics, drives, and fuel
requirements.  As a precursor to that (and whether or not anything ever
comes of the game), I've been working on a "calculator" that will allow
one to compute all the data tables required for the game.

It requires a lot of physical data, and it can't really be used for
industrial strength calculations, since it employs a lot of
approximations to make the calculations manageable (coplanar, prograde,
circular orbits), and some of the calculations are placeholders, but it
can still do a fair amount of stuff (all figures are in SI units):

max at oxygen:~/projects/adrift% python -i stella.py 
>>> info(lowEarthOrbit, lowMarsOrbit)
Source: low orbit around `Earth'
Destination: low orbit around `Mars'
Opportunities:
 Opportunity: Earth/Mars
  Angle: 0.773813615969 rad (44.3362543248 deg)
  Period: 67410366.2965 s
Transfers:
 Transfer: out of `low orbit around `Earth''
  Duration: 0.0 s
  Burns: 3250.27120897 m/s
 Transfer: Hohmann from `Earth' to `Mars'
  Duration: 22367816.9538 s
  Burns: 2943.59381931, 2647.9758885 m/s
 Transfer: into `low orbit around `Mars''
  Duration: 0.0 s
  Burns: 1450.74569639 m/s
Course: from `low orbit around `Earth'' to `low orbit around `Mars''
Duration: 22367816.9538 s
Deltavee: 10292.5866132 m/s

And it knows all sorts of other things, too:

>>> lowEarthOrbit.orbitalPeriodAroundPrimary()
5181.5057206353176 # s
>>> earth.rocheLimit()
556362389.03351605 # m
>>> pluto.insolation()/earth.insolation()
0.00064958695692894674 # Sun is that much dimmer from Pluto than 
                       # from Earth
>>> venus.temperature()/venus.idealTemperature()
2.249475368547301 # that's thermodynamic temperature ratio -- now 
                  # THAT'S a greenhouse effect!
>>> triton.angularRadiusOfPrimary()/earth.angularRadiusOfSecondary(moon)
15.335201130577547 # from Triton, Neptune looks 15 times bigger than
                   # the Moon from Earth
>>> pluto.atmosphereMass()
9220763709116.8496 # kg, computed from surface gravity and pressure
>>> io.tidalStrengthFromPrimary()/earth.tidalStrengthFromSecondary(moon)
19581.842788149675 # Jupiter's tides on Io are this much strong than
                   # the Moon's on Earth

And since I've recently integrated information on all named objects in
the Solar System, you can even ask about obscure asteroids:

>>> SYSTEM['Yamatotakeru'].distance()
408470876880.0 # m, distance from the Sun
>>> Course(earth, SYSTEM['Yamatotakeru']).deltavee()
11077.130833824534 # m/s

and on and on.

Since the calculator is distinct from the game itself, whatever happens
(or doesn't happen :-) with the game won't affect the availability of
the calculator when the time comes.  And yes, I'll be happy to release
it as open source ... :-).

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ Society attacks early when the individual is helpless.
\__/ B.F. Skinner
    CSBuddy / http://www.alcyone.com/pyos/csbuddy/
 A Counter-Strike server log file monitor in Python.




More information about the Python-list mailing list