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
}
}