ScriptedOrbit: what's wrong with this script? [Solved]

All about writing scripts for Celestia in Lua and the .cel system
Topic author
astro
Posts: 41
Joined: 27.10.2003
With us: 15 years 10 months

ScriptedOrbit: what's wrong with this script? [Solved]

Post #1by astro » 31.03.2013, 17:00

Hi,

The scripted orbit below (orbits.lua) is meant to generate the second Lagrange point (L2) of a pair of bodies:
it takes 5 arguments: Celestia name of body 1, Celestia name of body 2, Celestia name of THIS reference point (L2) used to retrieve the frame in which the orbit is defined, mass ratio of the body pair, bouding radius.

The ssc file test.ssc below defines L2 for two systems Sun and EMB (Earth-Moon barycenter defined in another SSC from JPL ephenmerides), Earth and Moon

However, the resulting reference points are not placed where they should: although their distances to the Sun (for Sun-EMB L2) and Earth (for Earth Moon L2) look about right, their direction is totally wrong: they are not even in the orbit plane of the second body of the pair.

What is wrong with the scipt?

Thank you,

orbits.lua

Code: Select all

function L2(t)
   -- Create a new table
   local orbit = {};
   
   -- Save the parameter list
   orbit.params = t;

   -- Set the required fields boundingRadius and position; note that position is actually a function
   orbit.boundingRadius =t.BoundingRadius;

   -- static variables for orbit function
   local object1
   local object2
   local object3orbitframe
   local uLY2km = 9466411.842; -- micro lightyears to kilometers
   local init=true
   local scale=1+math.pow(t.MassRatio/3.,1/3.)

   -- The position function will be called whenever Celestia needs the position of the object
   function orbit:position(tjd)
       if (init) then     -- on first call retrieves celestia objects
          object1=celestia:find(t.Object1)
          object2=celestia:find(t.Object2)
          -- retrieves orbit frame at current time
          -- we assume that we do not need to update this
          -- that is this orbit frame object is valid for all time
          object3orbitframe=celestia:find(t.Object3):orbitframe()   
          init=false     
       end
       -- position of objects converted from universal coordinates to orbit frame
       local pos1=object3orbitframe:to(object1:getposition())
       local pos2=object3orbitframe:to(object2:getposition())
       local v=pos2-pos1
       local pos=pos1+v*scale
       local x=pos:getx()*uLY2km
       local y=pos:gety()*uLY2km
       local z=pos:getz()*uLY2km
       return x,y,z
    end

    return orbit
end


test.ssc

Code: Select all

ReferencePoint "L2" "Sol"
{   

    ScriptedOrbit
    {
        Module "orbits"
        Function "L2"

        Object1 "Sun"
        Object2 "EMB"
        Object3 "L2"
        MassRatio 3.04043263333e-6
        BoundingRadius 200e6
    }
}

ReferencePoint "L2 Earth-Moon system" "Sol/Earth"
{   

    ScriptedOrbit
    {
        Module "orbits"
        Function "L2"

        Object1 "Earth"
        Object2 "Moon"
        Object3 "L2 Earth-Moon system"
        MassRatio 0.0123
        BoundingRadius 200e6
    }
}
Last edited by astro on 01.04.2013, 12:25, edited 1 time in total.

Avatar
jogad
Posts: 458
Joined: 17.09.2008
With us: 11 years
Location: Paris France

Re: ScriptedOrbit: what's wrong with this script?

Post #2by jogad » 31.03.2013, 20:54

Hi,

Coordinates system is not oriented in the same way for Scripted Orbits and script functions. :evil:

Instead the obvious (but wrong) return x,y,z instruction for the result of the orbit:position() try rather:

Code: Select all

return x, -z, y


:mrgreen:

Avatar
Chuft-Captain
Posts: 1771
Joined: 18.12.2005
With us: 13 years 9 months

Re: ScriptedOrbit: what's wrong with this script?

Post #3by Chuft-Captain » 01.04.2013, 05:09

Astro,

Are you aware of my Lagrange Points addon? - Click here, or on the link in my sig. below.

This may save you a lot of un-necessary work. :wink:

CC
"Is a planetary surface the right place for an expanding technological civilization?"
-- Gerard K. O'Neill (1969)

CATALOG SYNTAX HIGHLIGHTING TOOLS LAGRANGE POINTS

Topic author
astro
Posts: 41
Joined: 27.10.2003
With us: 15 years 10 months

Re: ScriptedOrbit: what's wrong with this script?

Post #4by astro » 01.04.2013, 12:25

jogad wrote:Hi,

Coordinates system is not oriented in the same way for Scripted Orbits and script functions. :evil:

Instead the obvious (but wrong) return x,y,z instruction for the result of the orbit:position() try rather:

Code: Select all

return x, -z, y


:mrgreen:

Thank you. It works now.

Chuft-Captain wrote:Astro,

Are you aware of my Lagrange Points addon? - Click here, or on the link in my sig. below.

This may save you a lot of un-necessary work. :wink:

CC

I am not really interested in coding a Lagrange points script. I just wanted to test a bit what are the possibilities of ScriptedOrbit.


Return to “Scripting”

Who is online

Users browsing this forum: 1 guest