Welcome, Guest. Please Login.
Gravity Simulator
11/19/17 at 00:53:46
News: Registration for new users has been disabled to discourage spam. If you would like to join the forum please send me an email with your desired screen name to tony at gravitysimulator dot com.
Home Help Search Login


Pages: 1
Send Topic Print
Outputting to a gsim file? (Read 3214 times)
EDG
Ultimate Member
*****


oh, crumbs!!!

Posts: 611
Gender: male
Outputting to a gsim file?
09/11/08 at 20:58:25
 
I was wondering how difficult it'd be to have my star system generator output files either directly to gsim format, or to another format that can be imported into GravSim. I can output the semimajor axis, eccentricity, inclination, mass, and radius of each planet in the system (and the mass and radius of the star), and when I'm entering the system by hand into gravsim I usually just randomise the other orbital elements so I can get the program to output that too.  
 
But I have no idea how to output that into gsim format. I've got a jovian that looks like this for instance in the gsim file:
 
Quote:

j2
6.44348750348166E-09
Star
8421631
40480000
-3519439073839.88
-1473435195199.97
0
5.78403882217595E-02
-0.173468798320911
0
0
0
0
0
Reserved for future use
Reserved for future use
Reserved for future use

 
This is the outer jovian in my "Interesting System" thread, which has orbital parameters as follows:
Quote:
Jovian 2: radius 20240 km (density 1215.66 kg/m3), sma 23.418 AU, ecc 0.116, inc 0, mass 0.022 Jupiters, random orbital parameters

 
The "40480000" line in the gsim is probably the diameter, but I don't know what the rest could be. Presumably XYZ coordinates of the planet's starting location in its orbit? How would I figure those out from the orbital parameters though?
 
Is there any info as to what the other lines here mean and how they are calculated from the input parameters? There's also a load of stuff at the top of the file about fonts and windows etc, would I need to output that too?
Back to top
 
 

(formerly known as Mal)
View Profile WWW   IP Logged
frankuitaalst
Ultimate Member
*****


Great site

Posts: 1507
Gender: male
Re: Outputting to a gsim file?
Reply #1 - 09/12/08 at 01:20:27
 
There's one person on Earth who can answer this  Smiley
j2  
6.44348750348166E-09  
Star  
8421631  
40480000  
-3519439073839.88  
-1473435195199.97  
0  
5.78403882217595E-02  
-0.173468798320911  
0  
My guess is : mass (rel to Star ) , reference body , ??? , diameter (m) , and then I think your jovian moves in the XY plane (m; m/s )  
I'm also anxious to see  when the time delay between Europe and California has done its job .  Smiley as the header is also mysterious to me.  
Back to top
 
 
Email View Profile   IP Logged
Tony
YaBB Administrator
*****




Posts: 1051
Gender: male
Re: Outputting to a gsim file?
Reply #2 - 09/12/08 at 08:43:28
 
I'll look at it over the weekend.
Back to top
 
 
Email View Profile WWW   IP Logged
Tony
YaBB Administrator
*****




Posts: 1051
Gender: male
Re: Outputting to a gsim file?
Reply #3 - 09/14/08 at 13:24:51
 
http://www.orbitsimulator.com/cgi-bin/yabb/YaBB.pl?num=1131749461/3#3
This old thread explains the .gsim file
 
I've built a stand-alone program that makes .gsim files from Horizons data.
http://www.orbitsimulator.com/cgi-bin/yabb/YaBB.pl?num=1182042588/0#0
You can use the same procedure it uses.  There are 5 blocks of code that you can download from the linked thread, that contain the .gsim file broken up into 5 pieces.  Combine them together into one file, while adding your custom data between them, and you should have a working .gsim file
 
Block 1 contains:
Code:
<GrAVITY>
<Distance Boxes>
</Distance Boxes>
<Orbit Boxes>
</Orbit Boxes>
<SData>
 1.52243884034745E-10 
 


 
Now you must add 1 line that expresses the time and date as seconds elapsed since January 1, 0000 (In linear fashion... forget about the transformation from Gregorian, where 14 days were lost or gained.)
 
Block 2 contains:
 
Code:
 1 
 0 
 0 
 1 
 205 
False
False
 0 
-10000 
 


 
Now you must add 1 line that contanis the filename and path of your gsim file
 
Block 3 contains:
Code:
False
 2489252.02339429 
True
 0 
 2 
-60 
-60 
 19320 
 14520 
True
False
 1 
 10 
True
False
True
True
 


 
Now you must add 2 lines.  The first contains the directory path, just like the last line you added, except for the filename.  The next is the path and filename, identical to the line you added between blocks 2 & 3.  There are certain circumstances where you would want these to be different, which is why you're outputting the same data virtually 3 times in a row, but it's for an abandoned feature.
 
Block 4 contains:
Code:
False
 0 
 0 
 0 
 0 
False
 116.1333 
 16777215 
 16 
 408 
</SData>
<Command Buttons>
 690 
 0 
 1350 
 0 
 2010 
 0 
 2670 
 0 
 3330 
 0 
</Command Buttons>
<Captions>

MS Sans Serif
 12 
 16711680 
False
False
False
False
 0 
 0 
 1 
 1 

MS Sans Serif
 13.5 
 255 
False
False
False
False
 0 
 0 
 1 
 1 

MS Sans Serif
 8.25 
 65280 
False
False
False
False
 0 
 0 
 1 
 1 

MS Sans Serif
 8.25 
 16711680 
False
False
False
False
 0 
 0 
 1 
 1 
</captions>
<Thrust Box>
</Thrust Box>
<Objects>
 
Floating
 0 

 0 
 0 
 0 
 0 
 0 
 0 
 0 
 0 
-8.507059E+37 
-3.718556E+30 
 0 
Reserved for future use
Reserved for future use
Reserved for future use
Reserved for future use
 
Sun
 332951.136956723 

 65535 
 1392000000 
 0 
 0 
 0 
 0 
 0 
 0 
 0 
 0 
 0 
Reserved for future use
Reserved for future use
Reserved for future use
Reserved for future use
 


 
The last 18 lines of this the data for the 1st object, the Sun.  If your central object is something other than the Sun, then you can modify block 4.
After this block, you must add all the data for your system's objects in the following format:
 
Code:
Sun 'Name
 332983.460559796 'mass in Earth masses
    'Reference object (in the case of the Sun, there is none)
 65535 'color
 1392000000 'diameter in meters
 13.8709262263439 'x position in meters
-36.0921109680809 'y position in meters
 0 'z position in meters
 4.23406988261737E-04 'x velocity * time step
-1.09455051316522E-03 'y velocity * time step
 0 'z velocity * time step
 0 'x direction (used for thrusting the object)
 0 'y direction
 0 'z direction
Reserved for future use 'In Beta, used for Continuous Orientation Reference Object
Reserved for future use
Reserved for future use
Reserved for future use
 
 


 
Then add block 5
Code:
</Objects>
<Auto Pilot>
 0 
</Auto Pilot>
</GrAVITY>
 


 
And now you should have a workable .gsim file.
 
You said you wanted to output by orbital elements, but the .gsim file wants state vectors.  You can use this code to convert them:
 
Ignore the inputs in the first line.  Add some lines of code to the beginning of your code that sets  
baryCenter = False
additionalMass = 0
timescale = 1
Masss = (give it the mass of your primary object in units of Earth masses)
Go to the lines:
Code:
a = objsma(object)
ec = objecc(object)
i = objai(object)
w0 = objaa(object)
o0 = objaan(object)
m0 = objman(object)
 


These are your inputs
replace objsma(object) with your object's semi-major axis in meters.  Do the same for the next 5 elements:
ec = eccentricity (no units)
i = inclination (degrees)
w0 = argument of periapsis (degrees)
o0 = longitude of ascending node (degrees)
m0 = mean anomoly (degrees)
 
 
The following lines are your output:
Code:
    objx(object) = X * 1000 + objx(objRefN(object))
    objy(object) = Y * 1000 + objy(objRefN(object))
    objz(object) = z * 1000 + objz(objRefN(object))
    objvx(object) = xd * 1000 + objvx(objRefN(object))
    objvy(object) = yd * 1000 + objvy(objRefN(object))
    objvz(object) = zd * 1000 + objvz(objRefN(object))
 


The *1000 is converting km into meters, and the +objx(objRefN(object)) is simply the x-position of your primary object.  Same for y, & z.  objvx(objRefN(object)) is the x-component of your primary object's velocity.  Same for y & z.
 
Here's the full code:
(I'll add it in the next post, as I've hit my max characters per post limit)
Back to top
 
 
Email View Profile WWW   IP Logged
Tony
YaBB Administrator
*****




Posts: 1051
Gender: male
Re: Outputting to a gsim file?
Reply #4 - 09/14/08 at 13:26:13
 
Here's the full code:
Code:
Sub ComputeStateVector(object As Integer, baryCenter As Boolean)
Dim a As Double
Dim ec As Double
Dim i As Double
Dim w0 As Double
Dim o0 As Double
Dim m0 As Double
Dim deg As Double
Dim X As Double
Dim Y As Double
Dim z As Double
Dim xd As Double
Dim yd As Double
Dim zd As Double
Dim pX As Double
Dim pY As Double
Dim pZ As Double
Dim yw As Double
Dim Cw As Double
Dim Sw As Double
Dim xdw As Double
Dim ydw As Double
Dim co As Double
Dim so As Double
Dim qx As Double
Dim qy As Double
Dim qz As Double
Dim j2 As Double
Dim re As Double
Dim n0 As Double
Dim eca As Double
Dim diff As Double
Dim eps As Double
Dim e1 As Double
Dim ceca As Double
Dim seca As Double
Dim edot As Double
Dim ci As Double
Dim si As Double
Dim swci As Double
Dim cwci As Double
Dim Masss As Double

On Error Resume Next


If Not baryCenter Then
    Masss = ObjMass(objRefN(object)) + AdditionalMass * timescale * timescale '/ timescale / timescale
Else
    Masss = ObjMass(objRefN(object))
    j = 0

    For k = 1 To objects
	  If objref(k) = objname(objRefN(object)) Then
		j = j + 1
		SystemElement(j) = k
		Masss = Masss + ObjMass(k)
	  End If
    Next k
	
    SystemElements = j

End If

deg = 180# / Pi

a = objsma(object)
ec = objecc(object)
i = objai(object)
w0 = objaa(object)
o0 = objaan(object)
m0 = objman(object)




eca = m0 + ec / 2#
diff = 10000#
eps = 0.000001

While diff > eps
    e1 = eca - (eca - ec * Sin(eca) - m0) / (1 - ec * Cos(eca))
    diff = Abs(e1 - eca)
    eca = e1
Wend
ceca = Cos(eca)
seca = Sin(eca)
e1 = a * Sqr(Abs(1 - ec * ec))
xw = a * (ceca - ec)
yw = e1 * seca
edot = Sqr((398600.432896939 * Masss) / a) / (a * (1 - ec * ceca))
xdw = -a * edot * seca
ydw = e1 * edot * ceca
Cw = Cos(w0)
Sw = Sin(w0)
co = Cos(o0)
so = Sin(o0)
ci = Cos(i)
si = Sin(i)
swci = Sw * ci
cwci = Cw * ci
pX = Cw * co - so * swci
pY = Cw * so + co * swci
pZ = Sw * si
qx = -Sw * co - so * cwci
qy = -Sw * so + co * cwci
qz = Cw * si

X = xw * pX + yw * qx
Y = xw * pY + yw * qy
z = xw * pZ + yw * qz
xd = xdw * pX + ydw * qx
yd = xdw * pY + ydw * qy
zd = xdw * pZ + ydw * qz


Dim systemX As Double, systemY As Double, systemZ As Double
Dim systemVx As Double, systemVy As Double, systemVz As Double

If baryCenter Then
    systemX = objx(objRefN(object))
    systemY = objy(objRefN(object))
    systemZ = objz(objRefN(object))
	
    systemVx = objvx(objRefN(object))
    systemVy = objvy(objRefN(object))
    systemVz = objvz(objRefN(object))
	
    SystemMass = ObjMass(objRefN(object))
    For k = 1 To SystemElements
	  systemX = (objx(SystemElement(k))) - (objx(SystemElement(k)) - systemX) * (SystemMass / (ObjMass(SystemElement(k)) + SystemMass))
	  systemY = (objy(SystemElement(k))) - (objy(SystemElement(k)) - systemY) * (SystemMass / (ObjMass(SystemElement(k)) + SystemMass))
	  systemZ = (objz(SystemElement(k))) - (objz(SystemElement(k)) - systemZ) * (SystemMass / (ObjMass(SystemElement(k)) + SystemMass))
	  
	  systemVx = (objvx(SystemElement(k))) - (objvx(SystemElement(k)) - systemVx) * (SystemMass / (ObjMass(SystemElement(k)) + SystemMass))
	  systemVy = (objvy(SystemElement(k))) - (objvy(SystemElement(k)) - systemVy) * (SystemMass / (ObjMass(SystemElement(k)) + SystemMass))
	  systemVz = (objvz(SystemElement(k))) - (objvz(SystemElement(k)) - systemVz) * (SystemMass / (ObjMass(SystemElement(k)) + SystemMass))
		 
	  SystemMass = SystemMass + ObjMass(SystemElement(k))
    Next k
	
    dummy = Masss
    objx(object) = X * 1000 + systemX
    objy(object) = Y * 1000 + systemY
    objz(object) = z * 1000 + systemZ
    objvx(object) = xd * 1000 + systemVx
    objvy(object) = yd * 1000 + systemVy
    objvz(object) = zd * 1000 + systemVz
Else
    objx(object) = X * 1000 + objx(objRefN(object))
    objy(object) = Y * 1000 + objy(objRefN(object))
    objz(object) = z * 1000 + objz(objRefN(object))
    objvx(object) = xd * 1000 + objvx(objRefN(object))
    objvy(object) = yd * 1000 + objvy(objRefN(object))
    objvz(object) = zd * 1000 + objvz(objRefN(object))
End If


End Sub 'ComputeStateVector
 

Back to top
 
 
Email View Profile WWW   IP Logged
EDG
Ultimate Member
*****


oh, crumbs!!!

Posts: 611
Gender: male
Re: Outputting to a gsim file?
Reply #5 - 09/14/08 at 15:11:11
 
Ok, thanks Tony. I'll wade through that later and see what I can make of it Smiley
Back to top
 
 

(formerly known as Mal)
View Profile WWW   IP Logged
Tony
YaBB Administrator
*****




Posts: 1051
Gender: male
Re: Outputting to a gsim file?
Reply #6 - 09/14/08 at 22:23:42
 
Another option is to output your data to mimic a Systemic system, and then use the stand-alone program discussed here:
http://www.orbitsimulator.com/cgi-bin/yabb/YaBB.pl?num=1173346732/5#5
to build your gsim file.
Back to top
 
 
Email View Profile WWW   IP Logged
Pages: 1
Send Topic Print