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 Professional Discussion / Vectors, and magnitude, and orbits, oh my!

Author
Message
Burning Feet Man
18
Years of Service
User Offline
Joined: 4th Jan 2008
Location: Sydney, Australia
Posted: 15th Dec 2011 04:49 Edited at: 15th Dec 2011 04:51
I've been increasing my understanding of the DBPro language over the past few years. Learning bits here and there, then moving on to the next challenge!

Currently, I've decided to focus my energy on Vectors. After reading up and understanding basic concepts of Vectors, I decided that a picture says a thousand words, thus drew this up;



It's a straight forward 2D Planetary system, with one star, one planet and one moon. What I'm curious in is the mathematics behind such a system. Note that I've actually drawn it incorrectly, in that my drawn system is not cyclic in that the moon isn't effecting both the planets or the stars orbit (wobble as such) and the planet only has an effect on the moon, but not the star.

I need some guidance into tackling this problem, firstly 2D using Advanced 2D line tools, then eventually in 3D using both objects (and possibly mesh? I'm still not sure on what an object is in comparison to a mesh).

Looking forward to some advice, or some links to the past!

In the mean time I'll continue to tell myself that when I drop an apple, the Earth falls up towards the apple ever so slightly!

Cheers,
BFM

EDIT:
Note that I'm competent with using Advanced2D commands and Vector2 & Vector3 commands are making a lot of sense.

Help build an online DarkBASIC Professional help archive.
DarkBasic Help Wikia
Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 15th Dec 2011 06:18
Using advanced 2d would be a lot harder to deal with. The reason for this is the difference between screen space and world space. world space is like when you have an object at (2.4,4,-5.2), but this point may show up on the screen as pixel (500,600), and the transformation to get there is complicated in 3d. Not so complicated in 2d, but still not easy without a familiarity with matrix equations.

I'm kind of confused: Do you want to simulate things like the moons interaction with the sun? There's a HUGE difference between a simulation and a model.

If you want to have a simulation, you need to worry about things like position vectors, velocity and acceleration vectors, and mass. If you want to create a model, then you have to worry about things like direction and rotation.

This is a basic "model":



that "Rotate_Vector2" function probably seems like a little bit of magic. It's a rotation matrix applied to a vector that rotates the vector by "amount" degrees. So if you have the vector (1,0) and rotate it by 90 degrees, you get (0,1). If you have (0,1) and rotate it by 90 degrees, you get (-1,0) etc.

Simulations can get as fancy as you want. There are things called n-body simulations (I made one) that try to simulate the attraction of thousands of different masses. Universe Sandbox uses this kind of simulation in a more realistic way.

I'll give you a hint to start working on an unoptimized version of that n-body simulation. (unoptimized because the optimization is really complicated)

FOR each mass, you have an acceleration vector, a position vector, and a velocity vector. Forget rotation because that only comes into play when you have a physics system or are working on trying to create an accurate model.

Between two objects 1 and 2, the magnitude of the acceleration acting on object 1 is calculated by newton's inverse square law of gravity. Force=G*Mass1*Mass2/distance^2. Acceleration=force/mass, so a=G*m2/d^2. The direction of this force is in the direction of P2-P1, where P1/P2 are the objects position vectors (FROM p1 TO p2). So, normalize P2-P1, multiply it by the acceleration, and then you have a single acceleration vector for object 1. Do this for every other object (between objects 1 and 3, between objects 1 and 4, etc), and then add up all of the accelerations to get the actual acceleration.

Now the rest is the easy part. Velocity=Velocity+Acceleration*timestep, and
Position=Position+Velocity*timestep.

I was planning on writing up a vector/matrix tutorial over winter break, so stay tuned. Also, check out "Vectors Don't Bite!" if you haven't.

MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 15th Dec 2011 06:22 Edited at: 15th Dec 2011 06:23
Joining this thread as it will interest a friend... sorry I can not bring any insight to this... the maths involved seem simple but tk me its all gobbledeegoop

EDIT

hey Neuro... I got a pic for you lol...
Wow you wrote all that?... Will try to read it now...

Morcilla
23
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 17th Dec 2011 17:34
You might want to check some code-snippets like this:

n-body gravitational simulation

You can use vectors to describe the orbit path, but you can also use them to apply the gravitational forces...

MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 17th Dec 2011 18:30
nice one Morcilla

Burning Feet Man
18
Years of Service
User Offline
Joined: 4th Jan 2008
Location: Sydney, Australia
Posted: 18th Dec 2011 22:53
That's a pretty cool little sandbox by Neuro Fuzzy! I wonder how he's been going with it? It's really annoying that these forums close threads after a couple of weeks.

Help build an online DarkBASIC Professional help archive.
DarkBasic Help Wikia
Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 19th Dec 2011 01:13
aha, I haven't been able to work out collisions in a way that's physically accurate It looks realistic in the short-term it doesn't preserve energy/velocity.

Have you checked out vectors don't bite though?

Login to post a reply

Server time is: 2026-07-10 03:10:32
Your offset time is: 2026-07-10 03:10:32