ScriptedOrbit tutorial

All tutorials about Celestia go in here. For Celestia itself, add-ons, textures, scripting, etc.
Avatar
Cham M
Posts: 4324
Joined: 14.01.2004
Age: 60
With us: 20 years 10 months
Location: Montreal

Re: Three Lissajous curves

Post #21by Cham » 11.10.2009, 16:25

Fenerit,

the trouble I'm describing is seen when you follow the pink ball and watch Eros approaching (use the link I gave). Not the reverse. The video above can't show the problem.
"Well! I've often seen a cat without a grin", thought Alice; "but a grin without a cat! It's the most curious thing I ever saw in all my life!"

Avatar
Topic author
Fenerit M
Posts: 1880
Joined: 26.03.2007
Age: 17
With us: 17 years 8 months
Location: Thyrrenian sea

Re: Three Lissajous curves

Post #22by Fenerit » 11.10.2009, 16:49

Cham wrote:Fenerit,

the trouble I'm describing is seen when you follow the pink ball and watch Eros approaching (use the link I gave). Not the reverse. The video above can't show the problem.

Cham, I see that, and I see also that a galaxy appear in my visual. They are math issues; there are tangents in the module. But as long as the motion is assigned to an object instead of a camera, this latter is free to accomplish another motion... :wink:
Last edited by Fenerit on 11.10.2009, 16:51, edited 1 time in total.
Never at rest.
Massimo

Avatar
Cham M
Posts: 4324
Joined: 14.01.2004
Age: 60
With us: 20 years 10 months
Location: Montreal

Re: Three Lissajous curves

Post #23by Cham » 11.10.2009, 16:51

Yep, the maths aren't right. But once it is solved, it could let the user to travel into a spaceship through the whole universe ! :mrgreen:

The scriptedOrbit introduces the posibility to move a spaceship between several stars ! :o
"Well! I've often seen a cat without a grin", thought Alice; "but a grin without a cat! It's the most curious thing I ever saw in all my life!"

Avatar
Topic author
Fenerit M
Posts: 1880
Joined: 26.03.2007
Age: 17
With us: 17 years 8 months
Location: Thyrrenian sea

Re: Three Lissajous curves

Post #24by Fenerit » 11.10.2009, 16:57

Well, indeed. But today my attitude was "sci-fi movies" like. I'm not a math genius, but also myself think that someone would develop more equations, so to say, to make a sort of "math pack" for these orbits.
Never at rest.
Massimo

Avatar
Cham M
Posts: 4324
Joined: 14.01.2004
Age: 60
With us: 20 years 10 months
Location: Montreal

Re: Three Lissajous curves

Post #25by Cham » 11.10.2009, 17:03

I'm playing with it right now. I'm changing the motion to all sorts of trajectories. I don't understand the syntax yet, though.
"Well! I've often seen a cat without a grin", thought Alice; "but a grin without a cat! It's the most curious thing I ever saw in all my life!"

Avatar
Cham M
Posts: 4324
Joined: 14.01.2004
Age: 60
With us: 20 years 10 months
Location: Montreal

Re: Three Lissajous curves

Post #26by Cham » 11.10.2009, 17:09

Ok, I now understand the maths. My test trajectory is working as expected. Expect some very cool new things from this technique ! :wink:

What are the units used in the SSC for all the parameters ? What are the units of PeriodX, Y and Z ?

And what about AmplitudeX, Y, Z ?

EDIT : I'll be able to define precessing orbits (relativistic perihelion advance for some pulsars, for example), volcano ejecta with CMOD sprites, solar protuberances, spiraling motion to a black hole, etc... and maybe even this :

http://antwrp.gsfc.nasa.gov/apod/ap060726.html

http://demonstrations.wolfram.com/MassT ... arSystems/
:mrgreen:
"Well! I've often seen a cat without a grin", thought Alice; "but a grin without a cat! It's the most curious thing I ever saw in all my life!"

Avatar
Cham M
Posts: 4324
Joined: 14.01.2004
Age: 60
With us: 20 years 10 months
Location: Montreal

Re: Three Lissajous curves

Post #27by Cham » 11.10.2009, 18:08

There's a math library there, which will be very usefull to built complicated orbits :

http://lua-users.org/wiki/MathLibraryTutorial

Fenerit, please, edit the title of this thread so it reads something like "Scripted Orbit Tutorial"...
Last edited by Cham on 11.10.2009, 18:29, edited 2 times in total.
"Well! I've often seen a cat without a grin", thought Alice; "but a grin without a cat! It's the most curious thing I ever saw in all my life!"

Avatar
Topic author
Fenerit M
Posts: 1880
Joined: 26.03.2007
Age: 17
With us: 17 years 8 months
Location: Thyrrenian sea

Re: Three Lissajous curves

Post #28by Fenerit » 11.10.2009, 18:17

I can't wait! :D Amplitude and Phase are in km, instead, for what concern Period it I'm not sure but might be days. Anyhow, I noticed a thing: for speed movements in realtime is best to deal with the last decimals as were "frame rates" i.e 24, 25, 29.7, 30 fps.

Ahem, I don't know how to do for changing the title of the topic... :mrgreen:
Never at rest.
Massimo

Avatar
Cham M
Posts: 4324
Joined: 14.01.2004
Age: 60
With us: 20 years 10 months
Location: Montreal

Re: Three Lissajous curves

Post #29by Cham » 11.10.2009, 18:27

Fenerit wrote:I don't know how to do for changing the title of the topic...

Just edit your first message. The title is available there.
"Well! I've often seen a cat without a grin", thought Alice; "but a grin without a cat! It's the most curious thing I ever saw in all my life!"

Avatar
Topic author
Fenerit M
Posts: 1880
Joined: 26.03.2007
Age: 17
With us: 17 years 8 months
Location: Thyrrenian sea

Re: ScriptedOrbit tutorial

Post #30by Fenerit » 11.10.2009, 18:33

The title of this topic has been changed from "Three Lissajous curves" to "ScriptedOrbit tutorial".
Never at rest.
Massimo

Avatar
Cham M
Posts: 4324
Joined: 14.01.2004
Age: 60
With us: 20 years 10 months
Location: Montreal

Re: ScriptedOrbit tutorial

Post #31by Cham » 11.10.2009, 18:41

Now, someone needs to state the exact units of all variables used in the SSC, for any scripted orbit :

1. Time variable "t" (is it in "days" of 24 hours ?)
2. Amplitude (km ?)
3. Phase (degrees ? Radians ??)
4. PeriodX... (I guess it's the same unit as for the time variable ?)

Are the units dependant of the reference frame ?

And can we introduce any other parameters in the SSC ? For example, the unitless parameters called "Damping" and "Omega" below :

Code: Select all

"TestBall" "Sol/Eros"
{
   Class "spacecraft"
   Radius 1
   Color [ 1 0 1 ]

   OrbitFrame { BodyFixed { Center "Sol/Eros" } }
   BodyFrame { BodyFixed { Center "Sol/Eros" } }
 
   ScriptedOrbit {
      Module "Test_trajectory"
      Function "Test_trajectory"

      PeriodX      1
      PeriodY      1
      PeriodZ      1
      PhaseX      0
      PhaseY      0
      PhaseZ      0
      AmplitudeX   100
      AmplitudeY   100
      AmplitudeZ   100
      Damping       5
      Omega        2
   }
}

EDIT : Apparently, the answer to the last question is YES, according to some test I just made a min ago. So this is good.

For reference : Maths library there :
http://lua-users.org/wiki/MathLibraryTutorial
"Well! I've often seen a cat without a grin", thought Alice; "but a grin without a cat! It's the most curious thing I ever saw in all my life!"

Avatar
Topic author
Fenerit M
Posts: 1880
Joined: 26.03.2007
Age: 17
With us: 17 years 8 months
Location: Thyrrenian sea

Re: ScriptedOrbit tutorial

Post #32by Fenerit » 11.10.2009, 19:03

Sorry Cham, Phase cannot be in km, of course.
Never at rest.
Massimo

Avatar
Topic author
Fenerit M
Posts: 1880
Joined: 26.03.2007
Age: 17
With us: 17 years 8 months
Location: Thyrrenian sea

Re: ScriptedOrbit tutorial

Post #33by Fenerit » 11.10.2009, 19:24

A short description of ScriptedOrbit is here: http://en.wikibooks.org/wiki/Celestia/Trajectories#SampledOrbit ; Phase seem in radiants. t (current julian day)
Never at rest.
Massimo

Avatar
Cham M
Posts: 4324
Joined: 14.01.2004
Age: 60
With us: 20 years 10 months
Location: Montreal

Re: ScriptedOrbit tutorial

Post #34by Cham » 12.10.2009, 01:04

OMG ! This is pretty impressive ! Look at this UFO traveling all around the world.

Download link :
http://fsgregs.startlogic.com/Public_Files/Cham/UFO.zip (3.1 MB)

Image
Use this URL to follow the fast puppy !
cel://PhaseLock/Sol:Earth:UFO/Sol:Earth ... rc=0&ver=3

Accelerate time 10 fold, and get away to see the large scale motion all around the world. This orbit isn't circular (well, this is the whole point of a scriptedOrbit !). The parameters used in the SSC file could be changed (especially the Omega1 and Omega2 parameters), and see the various effects you can achieve. Talk about a non-geodesic path ! :mrgreen:
"Well! I've often seen a cat without a grin", thought Alice; "but a grin without a cat! It's the most curious thing I ever saw in all my life!"

Avatar
Cham M
Posts: 4324
Joined: 14.01.2004
Age: 60
With us: 20 years 10 months
Location: Montreal

Re: ScriptedOrbit tutorial

Post #35by Cham » 12.10.2009, 01:53

For the previous example, here's the SSC code used, and its scripted trajectory in a simplified form :

Code: Select all

"UFO" "Sol/Earth"
{
   Class "spacecraft"
   Mesh "UFO.cmod"
   Orientation [90 1 0 0]
   Radius 0.05
   Albedo 0.6

   OrbitFrame { BodyFixed { Center "Sol/Earth" } }
   BodyFrame { BodyFixed { Center "Sol/Earth" } }
 
   ScriptedOrbit {
      Module "UFO_trajectory"
      Function "UFO_trajectory"

      OrbitalRadius   6600
      OrbitalPeriod   0.003
      Omega1      5
      Omega2      -7
   }

   UniformRotation {
      Period 0.005
   }
}

# The code below is a constraint on the spacecraft orientation
Modify "UFO" "Sol/Earth"
{
   BodyFrame
   {
      TwoVector
      {
         Center "Sol/Earth/UFO"
         Primary
         {
            Axis "z"
            RelativePosition {
               Observer "Sol/Earth/UFO"
               Target "Sol/Earth"
            }
         }

         Secondary
         {
            Axis "-x"
            RelativeVelocity {
               Observer "Sol/Earth/OVNI"
               Target "Sol/Earth"
            }
         }
      }
   }
}


The scripted orbit :

Code: Select all

function UFO_trajectory(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

   -- Compute the bounding radius from the SSC parameters
   orbit.boundingRadius = t.OrbitalRadius

   -- The position function will be called whenever Celestia needs the position of the object
    function orbit:position(tjd)
   local t = tjd - 2451545.0
   local pi2 = math.pi * 2;

   local x = self.params.OrbitalRadius * math.cos(self.params.Omega2 * t / self.params.OrbitalPeriod) * math.cos(self.params.Omega1 * t / self.params.OrbitalPeriod)
   local y = self.params.OrbitalRadius * math.sin(self.params.Omega1 * t / self.params.OrbitalPeriod)
   local z = self.params.OrbitalRadius * math.sin(self.params.Omega2 * t / self.params.OrbitalPeriod) * math.cos(self.params.Omega1 * t / self.params.OrbitalPeriod)

   return x, y, z
    end

    return orbit
end
"Well! I've often seen a cat without a grin", thought Alice; "but a grin without a cat! It's the most curious thing I ever saw in all my life!"

Avatar
Topic author
Fenerit M
Posts: 1880
Joined: 26.03.2007
Age: 17
With us: 17 years 8 months
Location: Thyrrenian sea

Re: ScriptedOrbit tutorial

Post #36by Fenerit » 12.10.2009, 10:50

Interesting. 8) Now we can track airlines flies :mrgreen:
Instead, this code show rectilinear alternate motions along XYZ axis rispectively.

scriptorbit.ssc

Code: Select all

"Uniform X" "Sol/Eros"
{

   Class "spacecraft"
    Radius 1

   Color [ 1 0 0 ]

   OrbitFrame { BodyFixed { Center "Sol/Eros" } }
    BodyFrame { BodyFixed { Center "Sol/Eros" } }
   
   ScriptedOrbit
    {
        Module "uniform_motion"
        Function "uniform_motion"

        PeriodX       0.000025      
        PeriodY       0.000025      
        PeriodZ       0.000025
        PhaseX          0      
        PhaseY          0         
        PhaseZ          0         
        AmplitudeX       50   # length of motion in km      
        AmplitudeY       0         
        AmplitudeZ       0   
      
    }
}

"Uniform Y" "Sol/Eros"
{

   Class "spacecraft"
    Radius 1

   Color [ 1 0 0 ]

   OrbitFrame { BodyFixed { Center "Sol/Eros" } }
    BodyFrame { BodyFixed { Center "Sol/Eros" } }
   
   ScriptedOrbit
    {
        Module "uniform_motion"
        Function "uniform_motion"

        PeriodX       0.000025      
        PeriodY       0.000025      
        PeriodZ       0.000025
        PhaseX          0      
        PhaseY          0         
        PhaseZ          0         
        AmplitudeX       0         
        AmplitudeY       50   # length of motion in km      
        AmplitudeZ       0   
      
    }
}

"Uniform Z" "Sol/Eros"
{

   Class "spacecraft"
    Radius 1

   Color [ 1 0 0 ]

   OrbitFrame { BodyFixed { Center "Sol/Eros" } }
    BodyFrame { BodyFixed { Center "Sol/Eros" } }
   
   ScriptedOrbit
    {
        Module "uniform_motion"
        Function "uniform_motion"

        PeriodX       0.000025      
        PeriodY       0.000025      
        PeriodZ       0.000025
        PhaseX          0      
        PhaseY          0         
        PhaseZ          0         
        AmplitudeX       0         
        AmplitudeY       0         
        AmplitudeZ       50    # length of motion in km
      
    }
}


uniform_motion.lua module:

Code: Select all

function uniform_motion(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

   -- Compute the bounding radius from the amplitudes
   orbit.boundingRadius =
       math.sqrt(t.AmplitudeX * t.AmplitudeX + t.AmplitudeY * t.AmplitudeY + t.AmplitudeZ * t.AmplitudeZ)

   -- The position function will be called whenever Celestia needs the position of the object
   function orbit:position(tjd)
    local t = tjd - 2451545.0
   
   local x = self.params.AmplitudeX * math.sin (t / self.params.PeriodZ - self.params.PhaseZ) * math.cos (self.params.AmplitudeZ)
    local y = self.params.AmplitudeY * math.sin (t / self.params.PeriodZ - self.params.PhaseZ) * math.cos (self.params.AmplitudeX)
    local z = self.params.AmplitudeZ * math.sin (t / self.params.PeriodZ - self.params.PhaseZ) * math.cos (self.params.AmplitudeY)

       return x, y, z
    end
    return orbit
end
Never at rest.
Massimo

Avatar
Cham M
Posts: 4324
Joined: 14.01.2004
Age: 60
With us: 20 years 10 months
Location: Montreal

Re: ScriptedOrbit tutorial

Post #37by Cham » 12.10.2009, 17:02

Try this code. Gives lots of funny trajectories around a planet :

UFO_trajectory.lua code :

Code: Select all

function spherical_trajectory(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

   -- Compute the bounding radius from the SSC parameters
   orbit.boundingRadius = t.OrbitalRadius

   -- The position function will be called whenever Celestia needs the position of the object
    function orbit:position(tjd)
   local t = tjd - 2451545.0
   local pi2 = math.pi * 2;

   local Theta = 1/4 + self.params.LatAngle * math.cos(pi2 * self.params.LatFrequency * t / self.params.OrbitalPeriod);
   local Phi = self.params.LongFrequency * t + self.params.LongAngle * math.cos(pi2 * self.params.LongVariation * t / self.params.OrbitalPeriod);

   local x = self.params.OrbitalRadius * math.sin(pi2 * Theta) * math.cos(pi2 * Phi)
   local y = self.params.OrbitalRadius * math.sin(pi2 * Theta) * math.sin(pi2 * Phi)
   local z = self.params.OrbitalRadius * math.cos(pi2 * Theta)

   return x, y, z
    end

    return orbit
end


SSC code :

Code: Select all

"Mad UFO" "Sol/Earth"
{
   Class "spacecraft"
   Mesh "UFO.cmod"
   Orientation [90 1 0 0]
   Radius 0.05
   Albedo 0.6

   OrbitFrame { BodyFixed { Center "Sol/Earth" } }
   BodyFrame { BodyFixed { Center "Sol/Earth" } }
 
   ScriptedOrbit {
      Module "UFO_trajectory"
      Function "spherical_trajectory"

      OrbitalPeriod   0.03
      OrbitalRadius   6995   # Radius of the sphere, in km
      LongFrequency   300   # Main longitude frenquency
      LatFrequency   100   # Main latitude frequency
      LatAngle   0.02   # Max latitude angle, in units of 2Pi
      LongVariation   600   # Secondary longitude frequency
      LongAngle   0.01   # Longitude variation angle, in units of 2Pi
   }

   UniformRotation {
      Period 0.005
   }
}
"Well! I've often seen a cat without a grin", thought Alice; "but a grin without a cat! It's the most curious thing I ever saw in all my life!"

Avatar
Cham M
Posts: 4324
Joined: 14.01.2004
Age: 60
With us: 20 years 10 months
Location: Montreal

Re: ScriptedOrbit tutorial

Post #38by Cham » 13.10.2009, 00:53

Here's an update to the previous UFO addon (just replace the CELXX and SSC files with the ones below). The trajectory LUA files were cleaned and the parameters are a bit more general (to define motions on a sphere). We could do lots of interesting paths on a sphere with these. The SSC file is commented, so the parameters meaning should be clear.

Archive.zip
"Well! I've often seen a cat without a grin", thought Alice; "but a grin without a cat! It's the most curious thing I ever saw in all my life!"

Avatar
Cham M
Posts: 4324
Joined: 14.01.2004
Age: 60
With us: 20 years 10 months
Location: Montreal

Re: ScriptedOrbit tutorial

Post #39by Cham » 13.10.2009, 18:16

ROFL !

Try this one ! :lol:

Archive.zip
"Well! I've often seen a cat without a grin", thought Alice; "but a grin without a cat! It's the most curious thing I ever saw in all my life!"

Avatar
Topic author
Fenerit M
Posts: 1880
Joined: 26.03.2007
Age: 17
With us: 17 years 8 months
Location: Thyrrenian sea

Re: ScriptedOrbit tutorial

Post #40by Fenerit » 13.10.2009, 22:25

Your UFO has really engine problems... :lol:
Never at rest.
Massimo


Return to “Tutorials”