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.

Newcomers DBPro Corner / Orbital arithmetics

Author
Message
lucifer 1101
15
Years of Service
User Offline
Joined: 26th Jan 2009
Location: Melbourne, Australia
Posted: 5th Feb 2009 01:56
What would be the best algorithn to work out rotation/orbiting if i have

P1Orbit#=108.897 ` Days
P1Rotation#=18.8 ` Hours

i thaught of doing rotation devided by orbit but im still not sure if thats the way to go??
Kira Vakaan
15
Years of Service
User Offline
Joined: 1st Dec 2008
Location: MI, United States
Posted: 5th Feb 2009 03:17
As I'm not really sure what you're asking, I don't know if this is what you're looking for, but I've written a little example demonstrating an orbit and rotation based on time. Here:



When you run this code, you'll see a little sphere rotating about its axis while revolving around a bigger sphere. I had to convert your orbit period into hours for the sake of ease. After you have everything at a constant unit, you must decide how much actual time that unit represents. In the example, an "hour" passes every two frames.
lucifer 1101
15
Years of Service
User Offline
Joined: 26th Jan 2009
Location: Melbourne, Australia
Posted: 5th Feb 2009 08:45
thats really good thanks i will now go on to finishing rotation within the next day..
lucifer 1101
15
Years of Service
User Offline
Joined: 26th Jan 2009
Location: Melbourne, Australia
Posted: 5th Feb 2009 11:48 Edited at: 5th Feb 2009 12:43
ok now little question what if i wanted say a moon on that planet thats orbiting the sun..



EDIT: it would be cool to have a function for setting an orbits origin eg

SetOrbitOrigin(objnumber,x,y,z)

if anybody can do this it would be really cool..
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 5th Feb 2009 16:55
Since most astronomical units are in relation to Earth, where 1AU is from Earth to the Sun and any other planets are based on that, I will use the same system.

AU_ORBIT_DAYS and AU_ORBIT_MILLISECONDS basically mean a planet will take this many days to complete 1 orbit and will do so in this many seconds on the screen.

orbit# is calculated to put the number of days of a satellite's orbit in terms of AUs. So if you set the constant to 100 days, any satellite with an orbit of 100 days will be 1AU. If a satellite completes an orbit if fewer days, say 50, then it has 0.5AU. As 1AU takes AU_ORBIT_MILLISECONDS to complete its orbit on the screen, 0.5AU will take half as long and thus appear on the screen to move faster, assuming orbital distances were the same. A shorter orbital time with a much shorter orbital distance will appear to move the same or slower speed. Hope that makes sense so far. It's all about proportions.

After you have the orbital time in relation to the constant of 1 orbit being AU_ORBIT_DAYS, you can then calculate how many seconds it will take to complete that orbit (on screen) and that's stored in maxTime.

Next step is to calculate the current time along the orbital path, which is why you need to set a timestamp at the beginning of movement. Then simply position of the object.


For the revolution of the planet, examine the code below and you should be able to figure that out in pretty much the same way.

Note: I typed this up on my Mac, so it's untested.



If you want a moon to revolve around another planet, make another satellite object where the origin is the current position of its parent planet it's orbiting around.


Also, I used "revolution" to define the rotation of a planet. My terminology is a bit off on that since a revolution is technically the orbit of the planet around another body. Oops, my bad.

Your signature has been erased by a mod because it's larger than 600x120
Kira Vakaan
15
Years of Service
User Offline
Joined: 1st Dec 2008
Location: MI, United States
Posted: 5th Feb 2009 23:02 Edited at: 5th Feb 2009 23:05
Phaelax, the only mistakes I found with your code were in the definitions of maxTime and t#. You forgot parentheses around
and then you should've declared maxTime as a float to typecast the division but I understand you didn't test it out first.

I rewrote my example, so it now uses the system timer and not the number of frames to determine speed. The frame rate is now irrelevant. Also, I liked Phaelax's idea of creating a type for Satellites and incorporated it. The only real difference to the example is the method by which it keeps track of time. Here it is:



And if you wanted that function to set orbit origins like you said, I recommend creating an array to store all of your satellites in and then write a function to access them by index number. Alas DBPro can't really pass pointers to a function. Something like this:



Hope all this helps.

Edit: Forgot to mention that the example now shows a moon orbiting a planet as well, but you would've noticed that when you ran the code.
Another thing, if you set a satellite's OrbitPeriod or RotationPeriod to a negative number, it will orbit or rotate counter-clockwise.
lucifer 1101
15
Years of Service
User Offline
Joined: 26th Jan 2009
Location: Melbourne, Australia
Posted: 5th Feb 2009 23:04 Edited at: 5th Feb 2009 23:10
thanks heaps going over it now and attempting to make use of it, it looks quite complicated...

Edit1: sorry i didnt see your post but the same still applies..

im going to have to do a complete rewrite of how i declare my variables and setup the objects for rotation, but thanks anyway...
lucifer 1101
15
Years of Service
User Offline
Joined: 26th Jan 2009
Location: Melbourne, Australia
Posted: 5th Feb 2009 23:16
ok the first thing i tried to do was get your code to work and the moon did orbit the planet but the planet did not orbit the sun...

p.s. what are the %% signs for?
Kira Vakaan
15
Years of Service
User Offline
Joined: 1st Dec 2008
Location: MI, United States
Posted: 5th Feb 2009 23:16
Wow. There was an obvious problem with the little function I posted. No OriginY in Satellite...



All better.
Kira Vakaan
15
Years of Service
User Offline
Joined: 1st Dec 2008
Location: MI, United States
Posted: 5th Feb 2009 23:21 Edited at: 5th Feb 2009 23:23
Well, I do believe the planet did orbit the sun, just really slowly. Change the constant MilPerSimHour to 10.0 and everything will move much faster.

%% is the operator for modulus division. It basically gets the remainder. So, 7.3%%3.5=0.3 because 3.5 goes into 7.3 exactly two times with 0.3 left over. It's useful for wrapping one number around another. Like in this case, SimTime# will never exceed Planet.OrbitPeriod.

Edit: Well... it will, but in that one line, the result will never exceed Planet.OrbitPeriod.
lucifer 1101
15
Years of Service
User Offline
Joined: 26th Jan 2009
Location: Melbourne, Australia
Posted: 5th Feb 2009 23:28
ok cool now i can really see how it affects it thanks..

ill keep you all posted if i have any problems converting my code or if im successful, cheers...
lucifer 1101
15
Years of Service
User Offline
Joined: 26th Jan 2009
Location: Melbourne, Australia
Posted: 6th Feb 2009 15:10
whew almost successful, i did have a big doo doo earlier when nothing worked for it but i fixed that after a little rewrite.

Anyway now im up to the point of getting the moons to orbit planet 2 using



and it sortof works but it isnt really using the orbit distance and orbits inside the planet (i know i checked).

All i did was make a variable to check for the planets size and added that into calcultaing the distance.

Now im all ready for a release thankyou very much for that

p.s. should i actually add in collision before i release it or not, because it seems unimportant for this version?...
Kira Vakaan
15
Years of Service
User Offline
Joined: 1st Dec 2008
Location: MI, United States
Posted: 7th Feb 2009 10:42
Glad to hear things are coming along.

Well, I think collision would be nice. But if you're planning on using the built-in collision commands, I can't help you. Personally, and I believe this is a rather widely held opinion, I think the built-in commands are pretty lacking in capabilities. If you're not already, I suggest using Sparky's Collision DLL. Solved all of my problems.
lucifer 1101
15
Years of Service
User Offline
Joined: 26th Jan 2009
Location: Melbourne, Australia
Posted: 7th Feb 2009 10:46
i have decided to leave out collisions until they are needed (when i put landing on pretty much).

I have heard that the built in commands are lacking and have looked at sparkys DLL and i will get it when i need it, thank you

p.s. you can find the first release in the WIP forum its called Solar Exodus(WIP)

Login to post a reply

Server time is: 2024-11-25 10:30:52
Your offset time is: 2024-11-25 10:30:52