How Celestia calculates speed?

All about writing scripts for Celestia in Lua and the .cel system
Topic author
rinoa79
Posts: 42
Joined: 20.11.2007
Age: 44
With us: 16 years 7 months
Location: Milan, Italy

How Celestia calculates speed?

Post #1by rinoa79 » 01.10.2008, 15:41

I have writing a stupid script to understand how celestia calculates speed but there's something wrong!
The speed is always zero!
I have trying to look if there was some scripts that could help me but I have found nothing...

Code: Select all

earth = celestia:find("Sol/Earth")
position = earth:getposition()

obs = celestia:getobserver()
pos_obs = obs:setposition(position)

speed = obs:getspeed()

celestia:print("Speed = " ..speed)
wait(3.0)


Can somebody tell me where I made the mistake?
I'm learning yet... Sorry again for my stupid question... :oops:

Thank you in advance.

Vincent
Developer
Posts: 1356
Joined: 07.01.2005
With us: 19 years 5 months
Location: Nancy, France

Re: How Celestia calculates speed?

Post #2by Vincent » 01.10.2008, 16:25

Rinoa79,

First, lines 1, 2 and 4 of your script are useless.
Then, your script gets the observer's speed at one single time t0.
What you want here is a loop which continuously gets the
current observer's speed and then displays it:

Code: Select all

while true do
  obs = celestia:getobserver()
  speed = obs:getspeed()
  celestia:print("Speed = " ..speed)
  wait(0)
end
Note that getspeed return the speed value in microlightyears/s.
You'll have to make the required conversion if you want to display it using another unit.

You can terminate the script by typing the 'ESC' key.
@+
Vincent

Celestia Qt4 SVN / Celestia 1.6.1 + Lua Edu Tools v1.2
GeForce 8600 GT 1024MB / AMD Athlon 64 Dual Core / 4Go DDR2 / XP SP3

Topic author
rinoa79
Posts: 42
Joined: 20.11.2007
Age: 44
With us: 16 years 7 months
Location: Milan, Italy

Re: How Celestia calculates speed?

Post #3by rinoa79 » 01.10.2008, 18:43

Vincent wrote:Rinoa79,

First, lines 1, 2 and 4 of your script are useless.
Then, your script gets the observer's speed at one single time t0.
What you want here is a loop which continuously gets the
current observer's speed and then displays it:

Code: Select all

while true do
  obs = celestia:getobserver()
  speed = obs:getspeed()
  celestia:print("Speed = " ..speed)
  wait(0)
end
Note that getspeed return the speed value in microlightyears/s.
You'll have to make the required conversion if you want to display it using another unit.

You can terminate the script by typing the 'ESC' key.

Hi,
I have selected my object and then I have started your code but the speed is always zero. I have added a line where microlightyears are transformed in Km/s but I'm not sure if it is right.


Code: Select all

speed = speed*9466411.842

Vincent
Developer
Posts: 1356
Joined: 07.01.2005
With us: 19 years 5 months
Location: Nancy, France

Re: How Celestia calculates speed?

Post #4by Vincent » 01.10.2008, 19:23

rinoa79 wrote:I have selected my object and then I have started your code but the speed is always zero.
Actually, the getspeed method doesn't really return the speed of the observer,
but rather the speed of a virtual spacecraft in which would be placed the observer.
You can change the speed of this virtual spacecraft using the 'A' and 'Z' keys.

However, if what you want is to calculate the speed of the observer relative to an object,
you shouldn't use the getspeed method, but rather something like:

Code: Select all

while true do
   obs = celestia:getobserver()
   sel = celestia:getselection()
   dist1 = obs:getposition():distanceto(sel:getposition())
   t1 = celestia:gettime()
   wait(0.1)
   dist2 = obs:getposition():distanceto(sel:getposition())
   t2 = celestia:gettime()
   speed = (dist2 - dist1) / ((t2 - t1) * 86400)
   celestia:print(speed)
end
This will give you an average speed calculated between t1 and t2 such as dt = t2 - t1 ~ 0.1s
@+
Vincent

Celestia Qt4 SVN / Celestia 1.6.1 + Lua Edu Tools v1.2
GeForce 8600 GT 1024MB / AMD Athlon 64 Dual Core / 4Go DDR2 / XP SP3

Topic author
rinoa79
Posts: 42
Joined: 20.11.2007
Age: 44
With us: 16 years 7 months
Location: Milan, Italy

Re: How Celestia calculates speed?

Post #5by rinoa79 » 01.10.2008, 21:37

Actually, the getspeed method doesn't really return the speed of the observer,
but rather the speed of a virtual spacecraft in which would be placed the observer.
You can change the speed of this virtual spacecraft using the 'A' and 'Z' keys.

However, if what you want is to calculate the speed of the observer relative to an object,
you shouldn't use the getspeed method, but rather something like:

Code: Select all

while true do
   obs = celestia:getobserver()
   sel = celestia:getselection()
   dist1 = obs:getposition():distanceto(sel:getposition())
   t1 = celestia:gettime()
   wait(0.1)
   dist2 = obs:getposition():distanceto(sel:getposition())
   t2 = celestia:gettime()
   speed = (dist2 - dist1) / ((t2 - t1) * 86400)
   celestia:print(speed)
end
This will give you an average speed calculated between t1 and t2 such as dt = t2 - t1 ~ 0.1s

Thank you very much of your help!!
Now all it's clear!
Bye!

SU(3)xSU(2)xU(1)
Posts: 59
Joined: 05.05.2008
With us: 16 years 1 month

Re: How Celestia calculates speed?

Post #6by SU(3)xSU(2)xU(1) » 02.10.2008, 09:05

Vincent wrote:
rinoa79 wrote:I have selected my object and then I have started your code but the speed is always zero.
Actually, the getspeed method doesn't really return the speed of the observer,
but rather the speed of a virtual spacecraft in which would be placed the observer.
You can change the speed of this virtual spacecraft using the 'A' and 'Z' keys.

However, if what you want is to calculate the speed of the observer relative to an object,
you shouldn't use the getspeed method, but rather something like:

Code: Select all

while true do
obs = celestia:getobserver()
sel = celestia:getselection()
dist1 = obs:getposition():distanceto(sel:getposition())
t1 = celestia:gettime()
wait(0.1)
dist2 = obs:getposition():distanceto(sel:getposition())
t2 = celestia:gettime()
speed = (dist2 - dist1) / ((t2 - t1) * 86400)
celestia:print(speed)
end
This will give you an average speed calculated between t1 and t2 such as dt = t2 - t1 ~ 0.1s

Vincent,

Your script returns the radial speed and not the total speed. To have the total speed (which includes also the transversal speed) your code should look like that:

Code: Select all

while true do
obs = celestia:getobserver()
sel = celestia:getselection()
dist1 = obs:getposition()-sel:getposition()
t1 = celestia:gettime()
wait(0.1)
dist2 = obs:getposition()-sel:getposition()
t2 = celestia:gettime()
speed = ((dist2 - dist1):length()) / ((t2 - t1) * 86400)
celestia:print(speed)
end


Paul
"Physicists know what's important, but they don't know what is true. Mathematicians know what's true, but they don't know what is important."

Vincent
Developer
Posts: 1356
Joined: 07.01.2005
With us: 19 years 5 months
Location: Nancy, France

Re: How Celestia calculates speed?

Post #7by Vincent » 02.10.2008, 10:52

Paul,

Of course, you're right. Thanks !
@+
Vincent

Celestia Qt4 SVN / Celestia 1.6.1 + Lua Edu Tools v1.2
GeForce 8600 GT 1024MB / AMD Athlon 64 Dual Core / 4Go DDR2 / XP SP3

Topic author
rinoa79
Posts: 42
Joined: 20.11.2007
Age: 44
With us: 16 years 7 months
Location: Milan, Italy

Re: How Celestia calculates speed?

Post #8by rinoa79 » 02.10.2008, 15:07

Vincent,

Your script returns the radial speed and not the total speed. To have the total speed (which includes also the transversal speed) your code should look like that:

Code: Select all

while true do
obs = celestia:getobserver()
sel = celestia:getselection()
dist1 = obs:getposition()-sel:getposition()
t1 = celestia:gettime()
wait(0.1)
dist2 = obs:getposition()-sel:getposition()
t2 = celestia:gettime()
speed = ((dist2 - dist1):length()) / ((t2 - t1) * 86400)
celestia:print(speed)
end


Paul

Excuse me,
I didn't understand a piece of your code:

Code: Select all

speed = ((dist2 - dist1):length()) / ((t2 - t1) * 86400)

I have looked for this method [tex]length()[/tex] but I didn't find it.
What is its utility?
Is it the formula of the average tangential speed or the sum of both tangential and radial speed?

Mary

SU(3)xSU(2)xU(1)
Posts: 59
Joined: 05.05.2008
With us: 16 years 1 month

Re: How Celestia calculates speed?

Post #9by SU(3)xSU(2)xU(1) » 03.10.2008, 10:27

rinoa79 wrote:Excuse me,
I didn't understand a piece of your code:

Code: Select all
speed = ((dist2 - dist1):length()) / ((t2 - t1) * 86400)
I have looked for this method but I didn't find it.
What is its utility?
Is it the formula of the average tangential speed or the sum of both tangential and radial speed?

Mary

Mary,

In my code "dist2" and "dist1" are 3D vectors, that describes relative positions of the observer with respect to the selected object ("dist2" at time "t2" and "dist1" at time "t1"). "dist2 - dist1" is then a vector, which desribes the displacement of the observer in time period "t2 - t1". "(dist2 - dist1):length()" is the length of this vector, so it approximates the distance traveled by the observer in time period "t2 - t1". To calculate the total speed of the observer with respect to the selected object it is enough to divide the distance "(dist2 - dist1):length()" by time "t2-t1".

Another thing:

[tex]total speed = \sqrt{(transversal speed)^2+(radial speed)^2}[/tex]

I'm not sure, what do you mean by "tangential speed".

Paul
"Physicists know what's important, but they don't know what is true. Mathematicians know what's true, but they don't know what is important."

Topic author
rinoa79
Posts: 42
Joined: 20.11.2007
Age: 44
With us: 16 years 7 months
Location: Milan, Italy

Re: How Celestia calculates speed?

Post #10by rinoa79 » 06.10.2008, 19:11

Mary,

In my code "dist2" and "dist1" are 3D vectors, that describes relative positions of the observer with respect to the selected object ("dist2" at time "t2" and "dist1" at time "t1"). "dist2 - dist1" is then a vector, which desribes the displacement of the observer in time period "t2 - t1". "(dist2 - dist1):length()" is the length of this vector, so it approximates the distance traveled by the observer in time period "t2 - t1". To calculate the total speed of the observer with respect to the selected object it is enough to divide the distance "(dist2 - dist1):length()" by time "t2-t1".

Another thing:

[tex]total speed = \sqrt{(transversal speed)^2+(radial speed)^2}[/tex]

I'm not sure, what do you mean by "tangential speed".

Paul

Hi Paul,
what I call "tangential speed" is your "transversal speed", I think.
If I wanted to calculate only tangential speed, can you tell me what should I do?

Mary.

SU(3)xSU(2)xU(1)
Posts: 59
Joined: 05.05.2008
With us: 16 years 1 month

Re: How Celestia calculates speed?

Post #11by SU(3)xSU(2)xU(1) » 06.10.2008, 21:55

rinoa79 wrote:If I wanted to calculate only tangential speed, can you tell me what should I do?

Mary.

Mary,

You can use the following script:

Code: Select all

while true do
obs = celestia:getobserver()
sel = celestia:getselection()
pos1 = obs:getposition()-sel:getposition()
t1 = celestia:gettime()
wait(0.1)
pos2 = obs:getposition()-sel:getposition()
t2 = celestia:gettime()
dist = (pos2:length()+pos1:length()) / 2
tspeed = dist * math.acos((pos2 * pos1)/pos2:length()/pos1:length()) / ((t2 - t1) * 86400)
celestia:print(tspeed)
end


Paul
"Physicists know what's important, but they don't know what is true. Mathematicians know what's true, but they don't know what is important."

Topic author
rinoa79
Posts: 42
Joined: 20.11.2007
Age: 44
With us: 16 years 7 months
Location: Milan, Italy

Re: How Celestia calculates speed?

Post #12by rinoa79 » 07.10.2008, 07:49

[/quote]

Mary,

You can use the following script:

Code: Select all

while true do
obs = celestia:getobserver()
sel = celestia:getselection()
pos1 = obs:getposition()-sel:getposition()
t1 = celestia:gettime()
wait(0.1)
pos2 = obs:getposition()-sel:getposition()
t2 = celestia:gettime()
dist = (pos2:length()+pos1:length()) / 2
tspeed = dist * math.acos((pos2 * pos1)/pos2:length()/pos1:length()) / ((t2 - t1) * 86400)
celestia:print(tspeed)
end


Paul[/quote]
Thank you very much for your help Paul! :D
Mary.

Topic author
rinoa79
Posts: 42
Joined: 20.11.2007
Age: 44
With us: 16 years 7 months
Location: Milan, Italy

Re: How Celestia calculates speed?

Post #13by rinoa79 » 09.10.2008, 16:03

SU(3)xSU(2)xU(1) wrote:Mary,

You can use the following script:

Code: Select all

while true do
obs = celestia:getobserver()
sel = celestia:getselection()
pos1 = obs:getposition()-sel:getposition()
t1 = celestia:gettime()
wait(0.1)
pos2 = obs:getposition()-sel:getposition()
t2 = celestia:gettime()
dist = (pos2:length()+pos1:length()) / 2
tspeed = dist * math.acos((pos2 * pos1)/pos2:length()/pos1:length()) / ((t2 - t1) * 86400)

celestia:print(tspeed)
end


Paul

Excuse Paul,
I have controlled again your code. I think that a line is wrong. Can you tell me if I'm made a mistake?
For me the right line is:

Code: Select all

tspeed = dist * math.acos((pos2 * pos1)/pos2:length()*pos1:length()) / ((t2 - t1) * 86400)

Mary

SU(3)xSU(2)xU(1)
Posts: 59
Joined: 05.05.2008
With us: 16 years 1 month

Re: How Celestia calculates speed?

Post #14by SU(3)xSU(2)xU(1) » 09.10.2008, 16:44

rinoa79 wrote:Excuse Paul,
I have controlled again your code. I think that a line is wrong. Can you tell me if I'm made a mistake?
For me the right line is:

Code: Select all
tspeed = dist * math.acos((pos2 * pos1)/pos2:length()*pos1:length()) / ((t2 - t1) * 86400)
Mary

Mary, your code is wrong, because "pos1:length()" is placed in the numerator and not in the denominator. I can give you a correct, alternative version of this line, which is equivalent to my original one:

Code: Select all

tspeed = dist * math.acos((pos2 * pos1)/(pos2:length()*pos1:length())) / ((t2 - t1) * 86400)


Paul
"Physicists know what's important, but they don't know what is true. Mathematicians know what's true, but they don't know what is important."

Topic author
rinoa79
Posts: 42
Joined: 20.11.2007
Age: 44
With us: 16 years 7 months
Location: Milan, Italy

Re: How Celestia calculates speed?

Post #15by rinoa79 » 09.10.2008, 16:56

SU(3)xSU(2)xU(1) wrote:
Mary, your code is wrong, because "pos1:length()" is placed in the numerator and not in the denominator. I can give you a correct, alternative version of this line, which is equivalent to my original one:

Code: Select all

tspeed = dist * math.acos((pos2 * pos1)/(pos2:length()*pos1:length())) / ((t2 - t1) * 86400)


Paul

Hi Paul,
I forgot parenthesis. In your previous version there was a "slash" instead "asterisk".
:D
Now all it's clear!
Thank you, Mary.


Return to “Scripting”