#### Archived

This topic is now archived and is closed to further replies.

# simple math problem ...

This topic is 6165 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Bearing in mind that I'm mathmatically inept ... I'm trying to create a model of a spiral galaxy. I have generated a number of stars which lie within a circle in X and Y. These stars have an attraction to the X and Y axis which is good, as it creates the arm part of the galaxy ... however, there is no spiral structure. check out ... http://www.btinternet.com/~mark.shaxted/galaxy.jpg What I want to do is rotate every star around the origin, depending on how far they are from the origin which would create a nice spiral effect. ie - the further from the center, the more rotation. But I haven't got a clue how! Ideally I would like to be able to try diferent amounts of rotation to see different effects ... maybe the furthest stars get rotated around the origin by 90 degrees, 180, 270, 360, 720 etc, whilst any star at the origin would stay where it is. The distance from the origin of obviously sqr(X^2 + Y^2)/Radius of galaxy. How about a bit of c code? Many thanks Edited by - Shag on October 31, 2001 2:39:35 AM

##### Share on other sites
The basic behaviour of stars in a galaxy is for them to orbit around the centre according to the laws of physics. The most relevant equations are

gravitational force = GMm / r^2

F = ma

and a = rw^2

Combining these gives

GMm /r^2 = mrw^2

or

w^2 = GM/r^3

w = angular velocity around centre
G = gravitational constant
M = mass of galaxy/galactic centre
r = distance from centre

This mans that the closer the star is to the centre the faster it rotates, like the orbits of the planests in our solar system. And this explains the spiral structure.

Our galaxy may have started out very uniform. But something happened to knock holes in it, possibiy a collision with another galaxy or with black holes. Then over time as the galaxy rotatated these holes and the arms between them were wrapped around the centre as the stars near the centre wound around the centre more quickly.

##### Share on other sites
Thanks for the reply, but I don''t need anything so complicated!

I already have an XYZ position for each star.

Say I have three star positions (ignoring Z)

0,1
0,2
5,1.5

How would I work out how to rotate these points around the origin, assuming for example the radius of the galaxy was 10? (Also assume the I want to rotate between 0 and 180 degrees, depending on how far away the point is from the origin)

##### Share on other sites
erm ... I really am stupid!

what i really want is the formula to rotate a 2d point around the origin!

##### Share on other sites
Try out this:

new_x = sqrt(x²+y²)*cos(rotation_angle+arctan(y/x));
new_y = sqrt(x²+y²)*sin(rotation_angle+arctan(y/x));

This should do it...
if it doesn''t try using PI (3,141592...) instead of 180 when calculating the rotation angle (most math-libs work with radians instead of degrees).

------------------------------------------------------------
"To a computer, chaos is just another kind of order."

##### Share on other sites
Just adding the standard (matrix) way to rotate a point/vector around the z-axis:

  original position = x, y, zrotated position = u, v, wangle to rotate by = au = x*cos(a) - y*sin(a)v = x*sin(a) + y*cos(a)w = z

Ill explain it more throughoutly if needed, just ask..

JT

In reality, a galaxy spins faster the nearer you are to the center, not the farther you are.

  pi = 3.14159... d = sqr(x * x + y * y); a = kappa * pi / radius * (radius - d); a = a * a / pi * pi; nx = x * cos(a) - y * sin(a); y = y * cos(a) + x * sin(a); x = nx;

In this sample, ''kappa'' is a value that defines the speed of rotation of the galaxy. In my tests, a value of 0.3 was about right, but you will need to adjust this depending upon how fast you want your galaxy to be, and how fast it runs. (I tested the algorithm on VisualBasic, it''ll probably run much faster on C.)

After we''ve calculated the angle, we adjust to an exponential scale. Slow angles get slower, and fast angles get faster. Hopefully, this will convincingly simulate what would be happening if gravity was really in charge.

I''d recommend using gravity to make it totally realistic. It''s probably faster than calculating rotations, and isn''t notably harder to understand.

PS. I read the other day that our galaxy is colliding with another one, right now. (Although, when I say, right now, I actually mean several million years ago.) Fortunately for us, it''s much smaller than ours.

Signatures? We don''t need no steenking signatures!

##### Share on other sites
Actually it's been determined that the stars in spiral galaxies rotate at the same speed, regardless of their distance from the center.

The "arms" are formed by many years of star generation.

Edited by - Buster on October 31, 2001 10:05:24 AM

##### Share on other sites
So galaxies aren't subject to the law of gravity? I find that somewhat hard to believe. Could you provide a link to more info on this?

Signatures? We don't need no steenking signatures!

Edit: Momentarily forgot how to write English.

Edited by - Mayrel on October 31, 2001 11:17:58 AM

##### Share on other sites
My astronomy is a bit rusty. I did take an astronomy course in college back in, I think, 1988. Buster isn''t quite correct in saying stars in galaxies spin at the same speed regardless of distance. But he''s not totally wrong either, thanks to the mystical "dark matter". Their speed is related to the conservation of angular momentum. And as Mayrel reminds us, they are subject to gravity. Keep in mind that galaxies are enormous. The gravitational acceleration, due to the vast distribution of mass in a galaxy, varies in a way that is different from a few lightweight bodies around a concentrated central mass such as planets around a single star. Here''s a good page that discusses galactic rotation curves:

http://cfpa.berkeley.edu/darkmat/galrotcurve.html

To quote: "Looking at the rotation curves of galaxies, however, astronomers have found that rotational speeds do not fall off with distance as expected. Instead, the curves level off, and stars far away from the center of the galaxy move faster than expected."

sort of backs up Buster''s statement about speed-----for stars far away from the center but not near the center.

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.

1. 1
2. 2
Rutin
22
3. 3
4. 4
frob
18
5. 5

• 33
• 13
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
632565
• Total Posts
3007106

×