View Single Post
  #1  
Old May 26th 05, 03:36 AM
Gerald Kaszuba
external usenet poster
 
Posts: n/a
Default gravity simulator - initial galaxy positions

Hi there

I'm not sure if this is the right place to ask, but I've written an
open-source gravity simulator using the barnes hut (oct-tree) method
(It's called "gravit" - google it if you want to check it out). My math
isn't so good -- I'm trying to work out how to 'spawn' galaxies on an
abitrary angle. Right now I'm able to start them on the X, Y or Z plane.
I'll write some psudeocode to explain myself better:

for each particle
distanceFromCenter = random(0 to galaxyRadius)
angle = random(0 to 2 * pi)
position.x = cos(angle) * distanceFromCenter
position.y = sin(angle) * distanceFromCenter
position.z = 0
velocity.x = cos(angle + pi / 2) * distanceFromCenter * 0.0001
velocity.y = sin(angle + pi / 2) * distanceFromCenter * 0.0001
velocity.z = 0
next

It looks like this:
http://gravit.slowchop.com/screenies/spiral-galaxy.jpg

That creats a circlular pattern of random particles, with velocities
going at a perpendicular angle to the center -- but only on the Z plane.
How can I rotate the galaxy to not be fixed to a plane, but a random angle?

Thanks

Gerald