XStar by Wayne Schlitt, wayne@midwestcs.com


This program "solves" the n-body problem, and displays the results on
the screen.  It starts by putting a bunch of stars on the screen, and
then it lets the inter-body gravitational forces move the stars
around.  The result is a lot of neat wandering paths, as the stars
interact and collide.

XStar can be used to animate the root window, as a screen saver or just
to display stuff in a regular window.



All comments, bug reports, bug fixes, enhancements, etc are welcome.
Send them to me at wayne@midwestcs.com.


This program is really a heavily modified version of XGrav, which was
written by David Flater (dave@case50.ncsl.nist.gov) and posted to
alt.sources on 1/21/95.  I liked the program enough that I was really
interested in it, but I didn't like it enough to leave it alone.  The
idea was Dave's, but I don't think too much of his code has been left
unchanged.  There is probably more untouched code from XSwarm, which
Dave used to implement the X port of his n-body problem solving code.

Like XGrav, any claim to this program that I have (which isn't much)
is under the GNU General Public License.  Have fun with it.


Changes to XStar
----------------
Version 1.0.0   3/12/95
        * initial release to alt.sources

Version 1.1.0   3/22/95
        * second release to alt.sources
        * the runtime 'd' command could cause a divide by zero
        * fixed up an error msg when allocating colors
        * portability patches for HPUX and AIXV3
        * GPL license is included in the shar file
        * switched to the rand48() family of random number generators
        * a 'multi-color' mode as added so that each star could have
          it's own color.  Can be enabled with the -m option.
          (From Jeffrey Mogul <mogul@pa.dec.com>)
        * run time commands 'm' and 'r' to toggle between multi-colored
          and rainbow modes. (From Jeffrey Mogul <mogul@pa.dec.com>)
        * Jeff Mogul also created a man page for XStar.
        * Don't start collapsars at exactly the COLLAPSAR mass to avoid
          FP rounding problems.
        * I found, to my shock and horror, that the code I inherited from
          xgrav implemented some sort of Aristotelean physics where
          heavier objects fell faster than lighter objects.  Converting to
          Newtonian physics made things slightly slower, but I think
          more interesting.
        * XGrav calculated the new locations of the stars by using the
          formula:  x(t) = x0 + v t
          This assumes that the velocity is constant (it isn't).
          Instead, I now use:  x(t) = x0 + v t + 1/2 a t^2 + 1/(2*3) (Dt a) t^3
          This assumes that the derivative of the acceleration is
          constant (it isn't).  At least it is _closer_ to being correct.
          Even dropping the term with the first derivative of the acceleration
          makes the movement _much_ less accurate.
        * changing to Newtonian physics makes the experimental bounce code
          work much better, but it still doesn't work very well.
        * added the -a and -m options to let people tweak the FV and FM
          values without having to recompile the system.

Version 2.0.0 8/27/95

        This was a major rewrite of XStar.  The three major parts of
        XStar namely, the initial star configuration code, the star
        movement code and the display code, have all undergone major
        reanalysis, redesign and recoding.  The whole program has been
        broken apart and modularized.

        Major changes:

        * The initial star configurations allow the star systems to
          last longer and have less early collisions.

        * The star initialization code works very well over a large range
          of initial numbers of stars.  No more tweaking of constants.

        * Many more types of special star configurations are now generated.

        * After testing many different methods of moving the stars, a
          faster and much more accurate method was selected.

        * The star bounce code now works reasonably well.

        * Star trails now erase themselves in a non-destructive way.

        * Star trails are now redrawn when the window is exposed.

        * Changing display modes now replots the screen in that mode.

        In addition, many many minor changes and bug fixes were made.


        James da Silva (jds@cs.umd.edu) contributed code to do self
        erasing trails, but I ended up not using it and instead
        implemented a different method that allowed for a
        non-destructive erasure.  The contribution was still very
        appreciated since it allowed me to see what it would look
        like with destructive erasing.


        Working on XStar has been a fun project that helped me refresh
        my understanding of classical mechanics (physics), differential
        equations, numerical analysis, X programming, and data structures.
        It has also given me some insight into the dynamics of star clusters
        galaxies and the physics of bouncing objects.

Version 2.1.0 9/04/95

	very minor portablity changes, bug fixes and spelling corrections.


Version 2.2.0 12/21/96

	A few minor bug fixes, misc cleanup, and a tweek or two to the
        star initialization code.

 	The documentation on the theory of the n-body problem has been
        moved out of theory_of_op.ltr and into the large poscript
        document n-body.ps
   


Changes from XGrav (vs XStar 1.0.0)
------------------

Performance improvements and bug fixes:

- XGrav used some sort of Aristotelian physics where heavier objects fell
  faster than light objects.  I switched to Newtonian physics.

- Lots of work was done to make the calculation of new star positions
  more efficient.  It looked like some of the collisions weren't
  working right, so I threw out Dave's calculations and re-derived
  my own.  I found out that Dave's code was correct, but slightly
  slower than mine and the problems with collisions was elsewhere.

  Anyway, after a lot of rewriting, the net result is that XStar can
  calculate many more interactions per second than XGrav could.

- The gravitational constant has been replaced with fudge factors that
  are easier to adjust.  These fudge factors have been cranked up to
  make the simulation many times more accurately.

  This increased accuracy prevents stars from shooting off at very
  high velocities instead of colliding like they should and it also
  allows collapsars to be orbited easier.  As a result, collapsars no
  longer eat most of the stars in the system, and thus the runtime 'd'
  command is much more useful.

  This change slows things down, but the other speed increases more than
  offset this.

- I changed the star trails from thick lines to single pixel width
  lines so that you can see more intricate interactions between the
  stars. I also buffer the output to the X server, and I don't
  check for X events as often.  This reduces the cpu consumed by the
  kernel and the X server by a huge amount.  This, in turn, allows you
  to run XStar at a very low priority and it won't have as big of an
  impact on other processes.  (The kernel and the X server always run
  at a high priority.)

- The default number of stars has been upped from 9 to 15.

- The delay option (-D msec) no longer slows the program down by a
  huge amount, so it is actually fairly useful now.

- Stars that float too far away from the center are now forgotten
  about.  They don't have much affect when they are way out there and
  they just slow things down.

The net result is that XStar simulates more stars, more accurately and
much quicker than XGrav could.


New bells and whistles  (XGrav vs XStar 1.0.0)
----------------------

- XStar tries to detect when "interesting" things are no longer
  happening on the screen and creates a new star system automatically.
  It no longer waits for a fixed amount of time before restarting.

- The initial star configuration code is much more sophisticated.  It
  randomly creates 0 to 4 collapsars and adjusts the masses and
  velocities of the initial stars to compensate.  It puts a
  counter-clockwise spin on the system so that the stars tend to orbit
  each other instead of just collapsing toward the center or flying
  off the screen.  The initial configuration seems to be fairly good
  for a wide range of the initial number of stars (-b num).

- The -v, -R command line options are new, as are the run time
  commands n, +, - and p.  The support of -r using the -g values is
  also new.



Known Bugs and Missing Features
-------------------------------

- It has been suggested (michael@dsndata.com) that it would be neat if
  collisions could cause the stars to break apart into several pieces.

  Maybe we could do something like if they collision is very softly, the
  particles stick together, but if they collide with a fair amount of
  force, they bounce.  If they collide with even more force, then they
  break apart.  This could let a single "system" evolve for quite a
  while.

- It would be nice if XStar detected heavy loads on the system and
  slowed down the updates during those times.  Unfortunately, it looks
  like about the most portable way of determining the loadavg would be
  to run uptime and parse the output.  This is kind of expensive to do.

  So, XStar works ok as a background process in the root window, but
  sometimes you have to hit 'p' to let other things get done sooner.

- I wasn't able to get the save-under feature to work in the root
  window, nor did the screen saver work correctly for me.  I think
  this is a problem with my (old) X Server, rather than a bug in the
  code.

- I think it would be neat to plug in the values for the solar system
  and see what happens.  By using the value for G and any arbitrary
  number of pixel distances, we can obtain conversion factors for the
  mass and distances.  Time is defined such that each iteration takes
  one unit of time

- It might be nice to use the mouse to create stars or temporary collapsars.
  You could click the mouse down and then the stars would follow the
  cursor around.  It would kind of be like XSwarm.

- Extend this to 3-d and use the color to denote the z distance

- need to add a toggle to change from short to long tails.  (maybe no tails
  also?)

- add a mode that uses the mass to determine the color of the star

- create positive and negative attraction like electrical forces

- keep track of the energy stored when two stars collide hand have
  them spontaneously decay into two stars, kind of like how
  sub-atomic particles do.

- create a circular star system with 2-3 rings of stars

- create a circular star system made of binary stars

- shouldn't plot_collapsars use a XDrawRectangle() instead of plotting
  the individual points?

- why doesn't the star_line stuff stay symmetric?  The points are carefully
  centered around zero...

- I would be nice if you could select what kind of star configuration you
  get.  This shouldn't be too hard to do now that most of this stuff is
  stored in sys_param_type and acted on by set_xmva().
