Skip to main content
GameDev.net gamedev.net
🔒 Locked

Spinning

Started by Mulligan May 23, 2002 at 8:03 PM 12 replies 700+ views
Original Post
Mulligan
Mulligan
If I have 10 points at random locations within a circle (which are stars) and each star is a class, of which contains a vector for direction. I want all the stars to be spinning in the same direction, so how do i determine what the vector should be?
Timkin
Timkin
If the stars are rotating about a fixed axis in a circular orbit then the velocity vector will be orthogonal (at right angles) to the radius vector (from the axis of rotation to the star). If the star has polar coordinates (r,theta) then the velocity vector will be directed along the unit vector


v = - sin(theta) i + cos(theta)j

for anti-clockwise rotation... and


v = sin(theta) i - cos(theta)j


for clockwise rotation.

The magnitude of the velocity (speed) will be a function of the radius. If you want all of the stars to orbit at the same angular rate, given by w (radians per second), then the tangential speed is given by


V = r*w


and so the velocity is given by


V = r*w*v


with the appropriate choice of v for the direction desired.

Good luck,

Timkin
Mulligan
Mulligan
I do appreciate the detailed (and correct) response, but I''m not using polar coordinates. Is there another using plain x,y,z coords?
Ronin_54
Ronin_54
...

Okay, in this case, you will probably want each star to have the same speed huh?

You need to use "corner speed". Just determine the amount of degrees-per-second that a star should move.

Then, determine the current distance between the center and the star, determine a new position that lies the same distance away from the center, but that has a corner of "corner speed * time-in-seconds" with the original line... That is your new position.
Timkin
Timkin
quote:
Original post by Mulligan
I do appreciate the detailed (and correct) response, but I'm not using polar coordinates. Is there another using plain x,y,z coords?


Yes. Use the simple tranformation from Cartesian to polar coordinates, then substitute these into the equations I gave you.

theta = arctan(y/x)

r = sqrt(x2 + y2)

Hence

V = sqrt(x2 + y2)*w*v


where


v = +/-(sin(arctan(y/x))i -cos(arctan(y/x))j )

...depending on rotation direction, as discussed earlier.

Timkin


[edited by - Timkin on May 25, 2002 12:03:17 AM]
Mulligan
Mulligan
I hate to keep asking questions when someone spends so much time writing a detailed response, but I''m still a bit confused.

I''ll begin by explaining in greater detail what I''m after. Every star is not rotating in a permanant fixed orbit. Every star is acted upon by gravity formulas etc. All I need is an initial vector specifying a direction for each star to begin in. The end result. If it was all in one function it would look like this

VECTOR vStartingPosition( 3.0f, 2.5f );
VECTOR vDirection = GetInitialDirection( vStartingPosition );

So simply put, I need to know how to write the GetInitialDirection function.
sQuid
sQuid
quote:
Original post by Mulligan
I''ll begin by explaining in greater detail what I''m after. Every star is not rotating in a permanant fixed orbit. Every star is acted upon by gravity formulas etc. All I need is an initial vector specifying a direction for each star to begin in.



It''s still not clear what you''re after. What do you mean by gravity formula? Is each star''s gravity affecting every other star (if so, you''re in for some interesting maths)? Or is each star under the gravitational influence of some central body like a black hole? What do you mean by "etc?"

In either case, to specify the initial setup you''re likely to need to initial position, initial velocity, and mass of each star.

Once you''re clear on what it is you''re doing it might be easier to help
Mulligan
Mulligan
Don''t worry about anything but the directional vector, that''s all I wan''t, nothing more. Don''t worry about the gravity stuff, I can do all that. I only said that to point out that the stars won''t be on a fixed axis, but nevermind that, it doesn''t concern my question at all.
Timkin
Timkin
quote:
Original post by Mulligan
Don''t worry about anything but the directional vector,



In WHAT direction??? You can start the star moving in any direction you like. You simply haven''t given enough information for us to go on!

As for using gravity to move all of your stars, you have one of two situations:

a) all stars attract each other; or,
b) all stars are attracted to a central gravitational source.

If it''s the former, give up now. Since the 3-body problem is not analytically solvable, then you''re not going to get very far with 1011 stars (the average number of stars in a galaxy)!!! You could simulate it numerically, but it won''t be stable without some serious damping of the orbits... which is just a fudge.

If b) is the case, then the stars will all share a common axis of rotation, even if they are in a decaying orbit! In which case, the above mathematics describes their motion. You can add a decay or growth rate in the orbital distance by setting dr/dt to be non-zero.

You should write out clearly the problem that you are trying to solve... or the scenario that you are trying to simulate. Put every conceivable piece of information about the system on paper. Then if you have problems working out how to do bits of the computation, ask us and please provide the details from your system outline!

Regards,

Timkin
Mulligan
Mulligan
Clearly, trying to re-explain myself is only digging my hole deeper and deeper. Thus.....I shall begin again.

I have a series of randomly distributed points within a circular area. Each point is a class containing a vector for position and a vector for direction. Before anything has moved, it should look similar to this:

width="424" height="314">

Each circle, excluding the center is a point, and the line represents the directional vector added to the current position. You can see how the direction of each point is perpenducular to the center, and they all point in a counter-clockwise direction.

What I can''t figure out, it how to determine the directional vector only knowing the current position. If a point was at (5,0) the directional vector would be (1,0). (It doesn''t have to be 1, but the idea is that it would be pointing strait up). If the point is at (0,4) the directional vector should be (-1,0). (Again the -1 may vary).

Remember, forget EVERYTHING i posted before, all it did was confuse everyone.(sorry)
sQuid
sQuid
Ah, you want the direction vectors to be at right angles to the position vectors.

If the position vector is (x,y) take the direction vector as (-y,x)
Timkin
Timkin
quote:
Original post by Mulligan

Remember, forget EVERYTHING i posted before, all it did was confuse everyone.(sorry)



Actually Mulligan, I think it was you who got confused. The answer to your question is the first thing I posted in my original response.


v = - sin(theta)i + cos(theta)j

for anti-clockwise rotation...

and

v = sin(theta)i - cos(theta)j

for clockwise rotation.

Since you don't wish to work in polar coordinates, I then gave the answer in Cartesian coordinates:


v = - sin(arctan(y/x))i + cos(arctan(y/x))j

for anti-clockwise rotation...

and

v = sin(arctan(y/x))i - cos(arctan(y/x))j

for clockwise rotation.

Of course I should have simplified this for you (sQuid did in his post, although without explaining himself)... since y=r*sin(theta) and x=r*cos(theta), we get


v = (-yi + xj )/sqrt(x2 + y2)


for anti-clockwise rotation and

v = (yi - xj )/sqrt(x2 + y2)

for clockwise rotation.

If you didn't understand why this was the answer you sought, then you should have said so, rather than suggest that I was confused. If you still don't understand I will be more than happy to explain.

Good luck with your simulation,

Timkin

[edited by - Timkin on May 27, 2002 4:28:35 AM]
johnb
johnb
quote:
Original post by sQuid
Ah, you want the direction vectors to be at right angles to the position vectors.

If the position vector is (x,y) take the direction vector as (-y,x)


Yes. You can get there by multiplying each point by the 2D rotation matrix

(0 -1)
(1 0)

To get rotations going the other way use

(0 1)
(-1 0)

instead (which gives (y, -x) follwing sQuid''s convention)
John BlackburneProgrammer, The Pitbull Syndicate

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.