Advertisement

Modeling orbit

Started by July 06, 2000 02:24 AM
3 comments, last by OberonZ 24 years, 5 months ago
Hi guys, I''m writing a particle engine and one of the things I''d like to do is to allow the placement of attractors of various gravitational forces. The end result is to have particles flying around and and getting caught in the gravity well of these attactors. More interesting is when there are two or more (carefully placed) attractors. Anyway, I''m having problems with the formulas. Newtown''s Law of Gravity says that F = G (m1 * m2) / (d^2) where F is the force, G the gravitational constant, m1 and m2 are the masses of the two objects, and d is the distance between them. However, I need to get x, y, and z values of the force. Currently, the next location of the particle is determined by taking the current location and adding a velocity vector to it. I need to figure out what gravity vector to subract from the end result. This is, of course, in 3D. In this case, let''s say that the mass of the particle is negligeble and the mass of the attractor is M. However, each attractor is really only a point, not an variable sized sphere. In other words, I''m not going to ultra realism here. A 1D object with mass must have an infine density, and that will pretty much kill all my particles My point in doing this is so that I can add "spice" to an otherwise typical particle engine, if anyone knows the answer to my dilemma, I would greatly appreciate the help. Thanks, -OberonZ PS: It''s pretty late here, so excuse me if I''m slightly incoherent ---
PAGE FAULT: Please insert "Swap File, Disk 2"
and press any key to continue.
---
PAGE FAULT: Please insert "Swap File, Disk 2"
and press any key to continue.
First off, the direction of the force of gravity is always from the attractee to the attractor, so in your case the direction would be from the particle to the sun.

Basically what Newton''s equation gives you is the magnitude of the gravity. So take the vector position of the sun, subtract the vector position of the particle, normalize the result and do a scalar multiply by your magnitude. This is the vector that you should add to the particle''s velocity.

Advertisement
You can apply F separately to each of the axis. In short calculate F(x), F(y) and F(z). then subtract them from each axis component i.e. x = x - F(x).

A - Attractor
P[n] - particle

F(x) = G (Am * P[n]m) / ((Ax - P[n]x)^2)
F(y) = G (Am * P[n]m) / ((Ay - P[n]y)^2)
F(z) = G (Am * P[n]m) / ((Az - P[n]z)^2)

You are going to have to play around with G. In reality Gravity is slow and ponderous. Increasing G will speed things up a little.

If you are interested, I have written a screen saver (2D, Windows) that lets you play around with attractors (and repulsors) for about 4 points to hundreds. I'll be more than glad to email you the source. email me if you would like it.


--------------------------
Carpe Diem

Edited by - DeltaVee on July 6, 2000 9:37:51 AM
D.V.Carpe Diem
Doh!

I should have thought of that. Thanks guys.

-OberonZ
---
PAGE FAULT: Please insert "Swap File, Disk 2"
and press any key to continue.
DeltaVee, could you e-mail me the source code please? Thank you!

[Edited by - Gladiator on December 18, 2008 7:57:40 PM]

This topic is closed to new replies.

Advertisement