Orbital Period Calculator
-
Topic authorW0RLDBUILDER
- Posts: 122
- Joined: 02.06.2010
- With us: 14 years 3 months
Orbital Period Calculator
I'm working on an orbital period calculator using Visual Basic 2008. I've figured out the equations, but I have no idea how to write the code (I'm a VB n00b.). Any help would be appreciated.
Re: Orbital Period Calculator
Do you want to set up a command-line application or one with a GUI? Windows Forms or WPF?
If you're trying to learn .Net coding, it might make more sense to start with a console application as may make it easier to figure out the nuts and bolts of the language without having to worry about setting up a GUI. There are probably quite a lot of good tutorials out there which should help you figure it out.
If you're trying to learn .Net coding, it might make more sense to start with a console application as may make it easier to figure out the nuts and bolts of the language without having to worry about setting up a GUI. There are probably quite a lot of good tutorials out there which should help you figure it out.
-
Topic authorW0RLDBUILDER
- Posts: 122
- Joined: 02.06.2010
- With us: 14 years 3 months
Re: Orbital Period Calculator
Windows Form. The only thing I need it to do is to calculate a planet's orbital period with the following series of calculations:
S*S*S=T
T/T=P
P/M=R
where S is SemiMajorAxis, T is the SemiMajorAxis cubed, P is the period it would have around Sol, M is the parent star's mass, and R is the final result. The only reason for a GUI is for the user to be able to modify the two input variables. I've tried doing this in Excel, but I was hopelessly confused. I tried in POV-Ray, but it always returned 1.You can tell I'm a total n00b to VB. The only functional programs I've made are web browsers and all the rest were either useless collections of controls or simple drawings.
EDIT: Figured out how to do this in Excel.
S*S*S=T
T/T=P
P/M=R
where S is SemiMajorAxis, T is the SemiMajorAxis cubed, P is the period it would have around Sol, M is the parent star's mass, and R is the final result. The only reason for a GUI is for the user to be able to modify the two input variables. I've tried doing this in Excel, but I was hopelessly confused. I tried in POV-Ray, but it always returned 1.You can tell I'm a total n00b to VB. The only functional programs I've made are web browsers and all the rest were either useless collections of controls or simple drawings.
EDIT: Figured out how to do this in Excel.
-
Topic authorW0RLDBUILDER
- Posts: 122
- Joined: 02.06.2010
- With us: 14 years 3 months
- t00fri
- Developer
- Posts: 8772
- Joined: 29.03.2002
- Age: 22
- With us: 22 years 5 months
- Location: Hamburg, Germany
Re: Orbital Period Calculator
What's the purpose of using such antiquated MS-specific code like VisualBasic and Exel??
It would be much more useful to write a short celx script (lua) for this exceedingly trivial formula. It's all there in Celestia and works in ALL operating systems for which Celestia is released!
A respective celx script could easily be integrated into Celestia, along with further results of interest based on the Kepler orbit approximation...In this way, it might be an educational excercise for people to compare the approximate, Kepler-based results directly with Celestia's more accurate internal orbit calculation
Notably, with celx, you may access Celestia's internal variables etc directly! Lua scripting may also be operated separately, after installation of the Lua package.
Fridger
It would be much more useful to write a short celx script (lua) for this exceedingly trivial formula. It's all there in Celestia and works in ALL operating systems for which Celestia is released!
A respective celx script could easily be integrated into Celestia, along with further results of interest based on the Kepler orbit approximation...In this way, it might be an educational excercise for people to compare the approximate, Kepler-based results directly with Celestia's more accurate internal orbit calculation
Notably, with celx, you may access Celestia's internal variables etc directly! Lua scripting may also be operated separately, after installation of the Lua package.
Fridger
-
- Posts: 105
- Joined: 04.03.2010
- With us: 14 years 6 months
Re: Orbital Period Calculator
Here's a quick CELX script that gives the Periods of bodies orbitting our Sun. Pretty straightforward and easy to use. But, as mentioned in the code below, as I started extending it to all bodies in Celestia, I unfortunately encountered what seem to be problems with the CELX getinfo() method, which I'll post on the Bugs page.
Anyway, this at least it seems to work for any bodies in orbit around our Sun. But to extend it to all of Celestia's objects we need the mass of any parent body to determine the Gravitational Parameter [ G*(m1+m2) or simplified to G*m1 when orbiting objects are of low mass compared to the parent parent.]
Hope this helps.
-Gary
Anyway, this at least it seems to work for any bodies in orbit around our Sun. But to extend it to all of Celestia's objects we need the mass of any parent body to determine the Gravitational Parameter [ G*(m1+m2) or simplified to G*m1 when orbiting objects are of low mass compared to the parent parent.]
Hope this helps.
-Gary
Code: Select all
-- ORBITAL PERIODS OF SOLAR SYSTEM PLANETS
--
-- a CELX script
--
-- by: Gary M. Winter. © 2010. All rights reserved.
--
-- for use with the incredible, free astronomy-simulation software
-- CELESTIA (www.shatters.net/celestia)
--
-- CELESTIA is by:
-- Chris Laurel, , Clint Weisbrod, Fridger Schrempp,
-- Christophe Teyssier, Grant Hutchison, Pat Suwalski,
-- Toti, Da Woon Jung, Hank Ramsey, Bob Ippolito,
-- Vincent Giangiulio and Andrew Tribick.
-- versions 1.4.1 and before: © 2001-2006 Chris Laurel
-- later versions: © 2001-2009 Celestia Development Team
--
--
-- This script gives your distance from the Sun and tells you
-- the Period of any planet whose orbital semi-major axis equals
-- that distance. Remember: as long as planets' masses are small
-- compared to that of their parent star, in a given star system two
-- planets with equal semi-major axes will have the same period;
-- it doesn't matter how eccentric their orbits may be. Therefore,
-- a planet in a highly elongated orbit with a semi-major axis of
-- 2 AU will have the same period as one with a circular orbit with
-- a radius of 2AU. A circular orbit is simply a special case where
-- the orbit's semi-major and semi-minor axes are the same.
--
-- Note for CELX programmers:
-- I started to extend this script to give orbital periods of all planets,
-- stars, moons etc. in Celestia but unfortunately found the following:
-- 1) Celestia's getinfo( ) method does not return a .mass key for stars;
-- 2) worse, even for planets and moons, getinfo( ) always returned zero
-- in its .mass key.
--
-- Code used for above:
-- Selection = celestia : getselection ( )
-- SelectionTable = Selection : getinfo ( )
-- SelectionMass = SelectionTable.mass
--
-- ---------------------------------------------------------
-- BACKGROUND
--
-- 1 AU = 149597869.4 km
-- mu = G ( m1 + m2 ) rigorously, the Gravitational Parameter
-- but m2 (the mass of planet, satellite, etc.) is usually very small compared to m1 (the mass of parent star, planet etc.)
-- so mu = G*m1 is substituted
-- ---------------------------------------------------------
-- CONSTANTS
PI = 3.14159265359
-- ---------------------------------------------------------
-- FUNCTIONS
function celestia_cleanup_callback()
-- empty function
end
function ShowObjectPeriod( )
SunPosition = Bodies[1] : getposition ( celestia:gettime( ) )
ViewerPosition = celestia : getobserver ( ) : getposition ( )
SemiMajorAxisInAU = SunPosition:distanceto ( ViewerPosition ) / 149597869.4
Period = math.sqrt( SemiMajorAxisInAU ^ 3 )
DistanceString = string.format(" Your distance from the Sun is: %5.6f AU.\n A solar planet in an orbit with a \"semi-major axis\"\n this large has a period of: %5.6f Years.\n Press the X key to eXit.", SemiMajorAxisInAU, Period )
celestia:print(DistanceString)
end -- of ShowObjectPeriod( )
function celestia_keyboard_callback(KeyPress)
local TrapKey = false
if KeyPress == "X" or KeyPress == "x" then
TrapKey = true
Exit = true
end
return TrapKey
end
-- ---------------------------------------------------------
-- START PROGRAM
Bodies = { }
Bodies[1] = celestia:find("Sol")
Exit = false
celestia:print(" ORBITAL PERIODS OF SOLAR SYSTEM PLANETS\n © 2010 Gary M. Winter\n All rights reserved.", 100 )
for i=1, 4 do
wait(0.7)
end
celestia:requestkeyboard(true)
repeat
wait(0)
ShowObjectPeriod( )
until Exit
celestia:print("\n\n Exiting \"ORBITAL PERIODS OF SOLAR SYSTEM PLANETS\" . . . May your journeys be joyous!", 3)
-- WE'RE DONE
1.6.1, Dell Studio XPS, AMD 2.7 GHz, 8 GB RAM, Win 7 64-bit, ATI Radeon HD 5670
1.6.0, Dell Inspiron 1720, Intel Core Duo 2 Ghz, 3 GB RAM, Win Vista, NVIDIA GeForce 8600M G/GT
1.4.1, Dell Dimension 4700, Pent-4 2.8 GHz, 512 MB RAM, Win XP SP2, Radeon X300
1.6.0, Dell Inspiron 1720, Intel Core Duo 2 Ghz, 3 GB RAM, Win Vista, NVIDIA GeForce 8600M G/GT
1.4.1, Dell Dimension 4700, Pent-4 2.8 GHz, 512 MB RAM, Win XP SP2, Radeon X300
Re: Orbital Period Calculator
OMG!! VB!?! COme on!!
Please use some decent language: C/C++. Of if you prefer scripting: Perl, Python, Lua.
And please use some decent toolkit: Qt Creator.
EDIT: added Perl, changed Qt addon for visual studio to Qt Creator.
Please use some decent language: C/C++. Of if you prefer scripting: Perl, Python, Lua.
And please use some decent toolkit: Qt Creator.
EDIT: added Perl, changed Qt addon for visual studio to Qt Creator.
Last edited by duds26 on 28.06.2010, 12:21, edited 2 times in total.
- t00fri
- Developer
- Posts: 8772
- Joined: 29.03.2002
- Age: 22
- With us: 22 years 5 months
- Location: Hamburg, Germany
Re: Orbital Period Calculator
duds26 wrote:OMG!! VB!?! COme on!!
Please use some decent language: C/C++. Of if you prefer scripting: Python, Lua.
And please use some decent toolkit: Qt addon for Visual Studio.
The (Trolltech) Qt add-in for Visual Studio I know about works ONLY for the commercial version of Visual Studio, NOT for the Express version that the Celestia developer team uses throughout. For Qt stuff, we use the Qtcreator IDE, of course. It collaborates perfectly with the VS_Express compiler
Actually you can't be serious to even request Qt widgets for calculating a trivial one-line formula...
As I wrote above, a tiny lua script (coded and tested in 5 minutes) is just adequate for such a simple task.
Finally, why didn't you include Perl on the scripting side?
![Wink ;-)](./images/smilies/icon_wink.gif)
+++++++++++++
Besides your overflowing wise remarks, we would be glad seeing also some neat graphical code from YOU at times, ...
+++++++++++++
F.
Re: Orbital Period Calculator
Hang on a minute here let's not bash the beginning-level programmer over their choice of programming language. And let's bear in mind that VB.Net and VBA are very different beasts. Yes the vendor-specific nature of the .Net environment is not ideal (to put it politely), but the .Net environment is actually quite a nice one to work with.
Apparently "bash Microsoft and all who dare associate with it" trumps encouraging new programmers round here. I think that's a bit of a shame really.
Apparently "bash Microsoft and all who dare associate with it" trumps encouraging new programmers round here. I think that's a bit of a shame really.
- t00fri
- Developer
- Posts: 8772
- Joined: 29.03.2002
- Age: 22
- With us: 22 years 5 months
- Location: Hamburg, Germany
Re: Orbital Period Calculator
ajtribick wrote:Hang on a minute here let's not bash the beginning-level programmer over their choice of programming language. And let's bear in mind that VB.Net and VBA are very different beasts. Yes the vendor-specific nature of the .Net environment is not ideal (to put it politely), but the .Net environment is actually quite a nice one to work with.
Apparently "bash Microsoft and all who dare associate with it" trumps encouraging new programmers round here. I think that's a bit of a shame really.
I agree as to bashing beginning programmers. Yet, as I suggested above, a few lines of Lua for that trivial 3rd Kepler law formula does not seem requesting too much ... Notably since Lua is already there in every copy of Celestia
![Wink ;-)](./images/smilies/icon_wink.gif)
As to VB.Net etc, I can't see much of a justification for coding tools in such a language., given that they should be supporting cross-platform Celestia! As far as I know, VB.net only works for Windows, right?
Incidentally, there is a large amount of competent "anti-writing" against Microsoft's Net philosophy/environment. The latter doesn't seem to be REALLY "catching on" (despite massive PR-pressure from MS)
Fridger
Re: Orbital Period Calculator
t00fri wrote:ajtribick wrote:Hang on a minute here let's not bash the beginning-level programmer over their choice of programming language. And let's bear in mind that VB.Net and VBA are very different beasts. Yes the vendor-specific nature of the .Net environment is not ideal (to put it politely), but the .Net environment is actually quite a nice one to work with.
Apparently "bash Microsoft and all who dare associate with it" trumps encouraging new programmers round here. I think that's a bit of a shame really.
I agree as to bashing beginning programmers. Yet, as I suggested above, a few lines of Lua for that trivial 3rd Kepler law formula does not seem requesting too much ... Notably since Lua is already there in every copy of Celestia
As to VB.Net etc, I can't see much of a justification for coding tools in such a language., given that they should be supporting cross-platform Celestia! As far as I know, VB.net only works for Windows, right?
Incidentally, there is a large amount of competent "anti-writing" against Microsoft's Net philosophy/environment. The latter doesn't seem to be REALLY "catching on" (despite massive PR-pressure from MS)
Fridger
Agree. The "trivial 3rd Kepler law formula" wrote in .NET framework with its result showed in a simple window, take the time to loading up as were an entire OS.
Never at rest.
Massimo
Massimo
-
Topic authorW0RLDBUILDER
- Posts: 122
- Joined: 02.06.2010
- With us: 14 years 3 months
Re: Orbital Period Calculator
The spreadsheet CAN be opened on OpenOffice.org Calc.
Also, here's the VB version:
http://tbh-1138.deviantart.com/art/Orbi ... -166958665
![Rolling Eyes :roll:](./images/smilies/icon_rolleyes.gif)
http://tbh-1138.deviantart.com/art/Orbi ... -166958665
Because I'm familiar with them. You got a problem with that?t00fri wrote:What's the purpose of using such antiquated MS-specific code like VisualBasic and Exel??
- t00fri
- Developer
- Posts: 8772
- Joined: 29.03.2002
- Age: 22
- With us: 22 years 5 months
- Location: Hamburg, Germany
Re: Orbital Period Calculator
I thought you wanted to learn a little bit about coding with this simple project? Sorry...W0RLDBUILDER wrote:The spreadsheet CAN be opened on OpenOffice.org Calc.Also, here's the VB version:
http://tbh-1138.deviantart.com/art/Orbi ... -166958665Because I'm familiar with them.t00fri wrote:What's the purpose of using such antiquated MS-specific code like VisualBasic and Exel??
You got a problem with that?
Yes, but never mind
![Wink ;-)](./images/smilies/icon_wink.gif)
Fridger
Re: Orbital Period Calculator
Finally, why didn't you include Perl on the scripting side?That's what WE use at Celestia for ALL our extensive data related tasks (for good reasons). Perl is certainly a most powerful and modern (obejct oriented) cross-platform scripting language.
+++++++++++++
Besides your overflowing wise remarks, we would be glad seeing also some neat graphical code from YOU at times, ...
+++++++++++++
F.
1) Didn't knew about Qt creator back then.
2)
I AM SERIOUS, you gotta love CODE SNIPPETS+TEMPLATES used right!Actually you can't be serious to even request Qt widgets for calculating a trivial one-line formula...
As I wrote above, a tiny lua script (coded and tested in 5 minutes) is just adequate for such a simple task.
3) Python claims to be more user-friendly, also they have worked on the IO-aspect recently (2.7, 3.0). Seems like Perl should be added.
3) I've coded an gui for something recently but has nothing to do with astronomy or other science or engineering field.
Still very much in the process of learning to program in several languages.
I don't have all day to be be buzzy with this kind of stuff. Have other stuff I must do.
Re: Orbital Period Calculator
Good idea.
Seriously, go for it!
I really don't see any reason why not.
You got to start somewhere.
Don't forget that this is not a choice between these two per se.
You can now start learning lua and later, when you feel the need for lower level programming, do C++.
That you say you need to start creating world right now looks to me as if you're making content.
And that should be in scripting subforum.
When you do decide to add stuff to Celestia itself.
You can choose to work together with the other developers.
And when you are ready, send in patches for Celestia.
Seriously, go for it!
I really don't see any reason why not.
You got to start somewhere.
Don't forget that this is not a choice between these two per se.
You can now start learning lua and later, when you feel the need for lower level programming, do C++.
That you say you need to start creating world right now looks to me as if you're making content.
And that should be in scripting subforum.
When you do decide to add stuff to Celestia itself.
You can choose to work together with the other developers.
And when you are ready, send in patches for Celestia.