Advertisement

Creating a galaxy ...

Started by October 26, 2001 08:32 AM
1 comment, last by Shag 23 years, 3 months ago
Hi I''m trying to create a spiral galaxy. What I need are random X,Y,Z coordinates for stars which lie within a spiral arm ... any ideas? Also ... how do you tell whether a point lies within an ellipsoid? Regards
Hiya...let me see if I can help

--
I''m trying to create a spiral galaxy. What I need are random X,Y,Z coordinates for stars which lie within a spiral arm ... any ideas?
--
Well... if you want it to be a full-size galaxy, you''re probably not going to want to randomly generate all of billions of stars. Instead, decide upon "sectors", perhaps the most straightforward is having sectors for each x,y,z value, then have a single galactic coordinate be approximately the size of a large solar-system and space beyond... (having its own internal sub xyz values). then, by some calculation upon the x,y,z, spawn a unique seed (if you''re going up to 999 for each coord, x*1000*1000 + y*1000 + z might work) with which to randomize....then, somehow include your seed and the distance (with NO external randomization)

What will happen is that you will seed the galaxy...since each randomized instance is based off a static number, everthing that "happens" will happen the same... since distance is included, you can include star density into your calculations.... admittedly, it''d be hard to include the (already incredibly slow) process of the stars themselves moving

--
Also ... how do you tell whether a point lies within an ellipsoid?
--
First, check to make sure it''s within the bounding box of the ellipsoid (a rect with the same dimensions of it...this saves a bit of time). Then, find the points on the ellipsoid with the same X coordinate as the point. Finally, if the Y coordinate of the point is between the Y coordinates of the two points you just got, it''s within... if it''s between or equal, it''s inclusively within

Hope that Helps
Abraxas - balezur@hotmail.com
Advertisement
Hmm. For an ellipsoid of eccentricity e, its center at (0,0) and its major axis on the horizontal:

      d = x*x + (y*y)/(e*e);      


If d is less than the square of the radius of the major axis, then the point is in the ellipsoid.

For an ellipsoid with a major axis that's at an angle, you need to rotate the points around the origin by the axis's angle. Actually, by the inverse of the angle.

  bool isInEllipsoid (vertex origin, float angle, float e, vertex point, float r){  float d;  // Adjust the point so that it is relative to (0,0)  point -= origin;  // A (2D) rotatation to align the major axis along the horizontal.  point.rotate(-angle);  // Adjust the y coordinate to turn the ellipsoid into a circle.  point.y /= e;  // How far from the center is the point?  d = point.x * point.x + point.y * point.y;  // The point is in the ellipsoid if it is nearer the  // center than the ellipsoid's perimeter.  if (d < r)    return true;  else    return false;}    


You can get galaxy-making code at http://www.gamedev.net/reference/articles/article1337.asp. It's okay, but it won't fool anybody.

I demand unsatisfaction!

Edit: Added isInEllipsoid.


Edited by - Mayrel on October 26, 2001 10:23:27 AM

Edited by - Mayrel on October 26, 2001 10:24:43 AM
CoV

This topic is closed to new replies.

Advertisement