Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / 2 objects to orbit eachother

Author
Message
bitJericho
22
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 5th May 2003 10:37 Edited at: 5th May 2003 10:37
Hey all, I've searched around, but am having real trouble trying to get 2 objects to orbit eachother using real values, and having accurate orbits by setting mass, velocities, x,y,z positions.. It needs to be in 3 dimensions... Any help would be appreciated..thanx

The 3D Modeler's Group : http://groups.yahoo.com/group/3dModeler/
The Unofficial DB Newsgroup : http://groups.yahoo.com/group/DBMag/
Hell IVIonkey
22
Years of Service
User Offline
Joined: 1st Apr 2003
Location: Outer Limits
Posted: 5th May 2003 11:41 Edited at: 5th May 2003 11:41
I did some searching around (about 2 minutes worth) and found this in the Google cache. Though it would be a lot easier to predetermine the orbit speeds and paths, this will do it all in real-time. Looks like, however, this won't work for binary orbiting systems: 1 object can orbit another, but they can't both orbit eachother (without some adaptations).

http://216.239.57.104/search?q=cache:FZLFdkAvCdIC:www.experts-exchange.com/Programming/Game_Development/AI_Physics/Q_20141983.html+3d+orbit+physics&hl=en&ie=UTF-8
bitJericho
22
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 5th May 2003 11:46 Edited at: 5th May 2003 11:46
i saw that but i couldn't adapt it to work

The 3D Modeler's Group : http://groups.yahoo.com/group/3dModeler/
The Unofficial DB Newsgroup : http://groups.yahoo.com/group/DBMag/
MrTAToad
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 5th May 2003 11:53
I've got a DLL that will calculate the coordinates for a complete circle. If you use Db you can get around the fact its only for one circle, by loading it in more than once.

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
ReD_eYe
22
Years of Service
User Offline
Joined: 9th Mar 2003
Location: United Kingdom
Posted: 5th May 2003 11:54
heres some code i just did it allows you to increase the speed at which the moon orbits aswell as the distance from the planet it is orbiting.


ARE YOU A 3D MODELER??? IF SO WE NEED YOU!!!
EMAIL [email protected] to work on the new Star Strike project!!!
bitJericho
22
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 5th May 2003 12:15 Edited at: 5th May 2003 12:16
that's cool you guys... but it's rather vital that two or more objects accurately orbit around eachother as the enduser will be able to see how his projectile will orbit around the second object, but how the second object will *wobble* if you will.. And ultimately there will be more then 2 objects acting upon eachother... And it will also have to act upon the third dimension... not in just 2 dimensions...

I know it's asking alot from you guys... but...but...i'd be your best friend forever*searches for the 'puppy dog face' smiley*

The 3D Modeler's Group : http://groups.yahoo.com/group/3dModeler/
The Unofficial DB Newsgroup : http://groups.yahoo.com/group/DBMag/
Hell IVIonkey
22
Years of Service
User Offline
Joined: 1st Apr 2003
Location: Outer Limits
Posted: 5th May 2003 13:02 Edited at: 5th May 2003 13:02
Perhaps you'd find something useful at this extensive site?

http://hyperphysics.phy-astr.gsu.edu/hbase/orbit.html
Hell IVIonkey
22
Years of Service
User Offline
Joined: 1st Apr 2003
Location: Outer Limits
Posted: 5th May 2003 13:44 Edited at: 5th May 2003 14:00
Let's see...

Each object has it's own force (and thus also velocity) vector. At each stage of the game loop, the new force of a given object will be the sum of the previous force vector and the vector induced by gravitation.

The force induced by gravitation comes from:
(G*m*n)/(r^2) = (m*v^2)/x
G is your gravitational constant (a fudge value). M is mass of the object already there. N is the mass of your projectile. R is the distance between them. V is the velocity of the object already there. R-X is the distance from the object already there to the center of rotation.
Solving this for X gives:
x=(r^2 * v^2)/(G*n)

If v is the velocity of the object already there, you'll get:
v^2 = (G*n*x)/r, or v=[(G*n*x)/r)]^(1/2)

This newfound velocity will be in the direction tangent the orbital shape. (However, I think you'd be better off recalculating the directional part of your vector based on the movement from old x,y,z to new x,y,z).

Convert the velocity to force. Add the original object force to the newfound force. Use this to determine where the object will be positioned. Repeat for the other object as well.

Very confusing, no?
bitJericho
22
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 5th May 2003 13:56
very

The 3D Modeler's Group : http://groups.yahoo.com/group/3dModeler/
The Unofficial DB Newsgroup : http://groups.yahoo.com/group/DBMag/
Hell IVIonkey
22
Years of Service
User Offline
Joined: 1st Apr 2003
Location: Outer Limits
Posted: 5th May 2003 14:01
Then I suggest getting some sample code from a galaxy-like particle physics simulator. This may deal with things even more alienating like octrees though, so good luck!
bitJericho
22
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 5th May 2003 14:12


The 3D Modeler's Group : http://groups.yahoo.com/group/3dModeler/
The Unofficial DB Newsgroup : http://groups.yahoo.com/group/DBMag/
Dr DooMer
22
Years of Service
User Offline
Joined: 22nd Dec 2002
Location: United Kingdom
Posted: 6th May 2003 01:14
Well, I don't know how much use this'll be, but I wrote a code snippet a while ago that I called a particle reactor. Really, it's just a load of spheres (although they could be any object) that exert a gravitational pull over each other. Sorry if it's not much good to you, but it's all I've got.

It looks pretty, too!

"I am a living, thinking entity who was created in the sea of information."
Hell IVIonkey
22
Years of Service
User Offline
Joined: 1st Apr 2003
Location: Outer Limits
Posted: 6th May 2003 02:30
I checked it out: very cool demo!

Looks even better if you change this:
dist#=(1/CALC_Distance(atom#(i,1),atom#(i,2),atom#(i,3),atom#(i2,1),atom#(i2,2),atom#(i2,3)))*0.002
to this:
dist#=(CALC_Distance(atom#(i,1),atom#(i,2),atom#(i,3),atom#(i2,1),atom#(i2,2),atom#(i2,3)))*0.002

However, reduce the number of objects to 2 or even 3 and you'll see there's no centrifugal force being applied to any object (crucial for orbits), just simple parabolic gravity. Also, you'd have to adapt this to take into account the mass of the particles.
Dr DooMer
22
Years of Service
User Offline
Joined: 22nd Dec 2002
Location: United Kingdom
Posted: 6th May 2003 06:16
Changing it to allow for different masses wouldn't be too hard - you'd just add in a couple more multiplications.

Making a true orbit is a little tricky, since you've got to get the speed and direction of motion just right. From what I can remember of physics lessons, the formula to calculate the required velocity isn't all that hard if you understand what's going on. I seem to think that, for multiple orbitting objects, you take the 'average' position, with regards to each object's mass. It works something like this:

If you've got one object(A) of mass 3 and a smaller object(B) of mass 2, you'd find the centre of their binary orbit with the calculation: ((position_a*3) + (position_b*2)) / 5. Those mathematically minded should notice that it's really just calculating a biased mean, giving object A a 3/2 bias. You'd do this calculation for each of the three axis and you'll then come out with the centre of orbit, which in this case should be closer to object A, meaning object B has a much wider orbit and hence has to go a lot faster. Now, all you've got to do is work out the orbit velocity for each object! If you don't understand all this, then let me know, and I'll write it out again in simpler terms.

Perhaps if you get the values right, my snippet would be able to perform a true orbit. The only deciding factor would be the impact of the little memory-saving shortcut that I took...

"I am a living, thinking entity who was created in the sea of information."
Hell IVIonkey
22
Years of Service
User Offline
Joined: 1st Apr 2003
Location: Outer Limits
Posted: 6th May 2003 07:21
Only problem with pure orbit equations is that the particles may not be in spherical or eliptical orbits. They could have hyperbolic tugs, or more likely, chaotic curves that may or may not resemble something similar to a true orbit. If you only have 2 objects though, you will be able to use simple orbit equations.

If only I remembered a universal formula for this besides F=(G*m1*m2)/(r^2), which is far too generic without adaptations. In an adaption of this equations though, m1 would be the total mass of the system (excluding m2), positioned (relating to r^2) as Dr DooMer has shown. m2 is the current particle that you need to calculate results for.

I suggest instead of modifying the stats for each particle as they are calculated, store them to a temporary array and then assign them to the particles once all the tests are done (the for loop has finished). This will be more accurate. I also suggest doing the calculations 1 or more times per SYNC so that they're more accurate than what you see on the screen.

My guess, however, no offense, is that Jerico2day has given up. Despite this possibility, I think it's interesting to solve this problem, for I may use it someday too.
bitJericho
22
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 6th May 2003 09:27
I have not yet given up, however, I don't need to figure a *true* orbit... i just need the ability to have a true orbit when the user points and fires and is lucky enough to get an object in orbit^_^

The 3D Modeler's Group : http://groups.yahoo.com/group/3dModeler/
The Unofficial DB Newsgroup : http://groups.yahoo.com/group/DBMag/
bitJericho
22
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 6th May 2003 09:55
ive been playing with your code Dr DooMer, but there are some probs with the formulas... i dunno... maybe someone else will have better luck lookin at this code... i took out some non-essential things...



The 3D Modeler's Group : http://groups.yahoo.com/group/3dModeler/
The Unofficial DB Newsgroup : http://groups.yahoo.com/group/DBMag/
Dr DooMer
22
Years of Service
User Offline
Joined: 22nd Dec 2002
Location: United Kingdom
Posted: 6th May 2003 16:53
Yeah - I haven't actually used scientific formulae for the snippet, I just used something that looks about right.

The 1/Distance part is because, as the particles get futher from each other, they exert less pull on each other. However, as any physicist will know, there's supposed to be a power of two in there as well. However, the underlying principals should all hold true. I think...

"I am a living, thinking entity who was created in the sea of information."
bitJericho
22
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 8th May 2003 00:15
ok..here's the code ive got so far...but i think the lines



are still off... any ideas?



The 3D Modeler's Group : http://groups.yahoo.com/group/3dModeler/
The Unofficial DB Newsgroup : http://groups.yahoo.com/group/DBMag/
bitJericho
22
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 13th May 2003 00:27
no ideas aye?

The 3D Modeler's Group : http://groups.yahoo.com/group/3dModeler/
The Unofficial DB Newsgroup : http://groups.yahoo.com/group/DBMag/
Hell IVIonkey
22
Years of Service
User Offline
Joined: 1st Apr 2003
Location: Outer Limits
Posted: 13th May 2003 00:51
Is that part you think is wrong supposed to be the centrifugal force? If so, that's really not how you do centrifugal force. Unfortunately, I couldn't give you a correct way to do it since I don't know a universal formula for an object in motion that may or may not be in an orbit.

Pricey
22
Years of Service
User Offline
Joined: 22nd Feb 2003
Location:
Posted: 15th May 2003 22:22
sorry, am i using your avatar?

I don't know i can't tell!
I push the button and run like hell!
bitJericho
22
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 22nd May 2003 02:18
yes :-s gets confusing sometimes lol, but feel free to use it... it's not my avatar per-se

The 3D Modeler's Group : http://groups.yahoo.com/group/3dModeler/
The Unofficial DB Newsgroup : http://groups.yahoo.com/group/DBMag/

Login to post a reply

Server time is: 2025-05-09 21:11:53
Your offset time is: 2025-05-09 21:11:53