Trojans

All about writing scripts for Celestia in Lua and the .cel system
Topic author
abramson
Posts: 408
Joined: 22.07.2003
With us: 21 years 6 months
Location: Bariloche, Argentina

Trojans

Post #1by abramson » 30.03.2007, 20:43

Hi, everybody. My first Lua excursion...

I tried to mark all Trojan asteroids, using a couple of criteria which didn't work. Not finding anything appropriate at Harald's documentation, I tried some guesses, so I am not surprised they didn't work. I'm sure somebody here would know the right method. I tried object:getinfo().orbitSemiMajorAxis (to decide according to orbit). I also tried object:getinfo().orbitPeriod (to decide according to the period of Jupiter), which IS documented by Harald, but it also didn't work. I would favor a filter according to orbit, which could easily be extended to paint families of asteroids with different colors.

Using only the Trojans as asteroids in Celestia (Selden's 4 ssc files, from Motherlode) works nice, of course, and gives a beautiful rendition of the swarms that accompany Jupiter. This is the code (it marks all the asteroids; my unsuccessfull attempts to filter by orbit or period are there, commented out).

Code: Select all

-- Mark all Jupiter Trojan asteroids

-- Initializations
celestia:unmarkall()
trojans = {}
trojans.len = 0
t=1

-- Fill trojans with solar system objects
function filltable(obj)
    local i, v
    local children = obj:getchildren()
    for i, v in children do
   
--    This does not work:   
--        r = v:getinfo().orbitSemiMajorAxis         
--        if v:type() == "asteroid" and r => 5.05 and r <= 5.40 then

--    This also does not work:     
--        p = v:getinfo().orbitPeriod
--        if v:type() == "asteroid" and p >= 11 and p<=12 then

--    This works, but watch out, it will mark ALL asteroids:
            if v:type() == "asteroid" then
            trojans[trojans.len] = v
            trojans.len = trojans.len + 1
        end
    end
end

-- Mark Trojans
function mark_trojans(trojans)
   while t < trojans.len do       
     trojans[t]:mark( "red", "disk", 1, 0.5 )
     t = t+1
   end
end

-- Main
--
sol = celestia:find("Sol")
filltable(sol)
mark_trojans(trojans)

-- Go to some nice viewpoint to see the swarms
celestia:select(sol)
observer = celestia:getobserver()
observer:gotolonglat(sol,0,0.5,5e9,10)
observer:follow(sol)
celestia:settimescale(5e6)
celestia:show("markers")
celestia:show("orbits")


Cheers,

Guillermo

hank
Developer
Posts: 645
Joined: 03.02.2002
With us: 23 years
Location: Seattle, WA USA

Re: Trojans

Post #2by hank » 31.03.2007, 02:02

abramson wrote:Hi, everybody. My first Lua excursion...

I tried to mark all Trojan asteroids, using a couple of criteria which didn't work. Not finding anything appropriate at Harald's documentation, I tried some guesses, so I am not surprised they didn't work. I'm sure somebody here would know the right method. I tried object:getinfo().orbitSemiMajorAxis (to decide according to orbit). I also tried object:getinfo().orbitPeriod (to decide according to the period of Jupiter), which IS documented by Harald, but it also didn't work. I would favor a filter according to orbit, which could easily be extended to paint families of asteroids with different colors.

I don't think orbitSemiMajorAxis is included in getinfo. But I believe orbitPeriod would work if you used days instead of years.

- Hank


Return to “Scripting”