Page 1 of 1

How Celestia calculates speed?

Posted: 01.10.2008, 15:41
by rinoa79
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.

Re: How Celestia calculates speed?

Posted: 01.10.2008, 16:25
by Vincent
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.

Re: How Celestia calculates speed?

Posted: 01.10.2008, 18:43
by rinoa79
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

Re: How Celestia calculates speed?

Posted: 01.10.2008, 19:23
by Vincent
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

Re: How Celestia calculates speed?

Posted: 01.10.2008, 21:37
by rinoa79
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!

Re: How Celestia calculates speed?

Posted: 02.10.2008, 09:05
by SU(3)xSU(2)xU(1)
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

Re: How Celestia calculates speed?

Posted: 02.10.2008, 10:52
by Vincent
Paul,

Of course, you're right. Thanks !

Re: How Celestia calculates speed?

Posted: 02.10.2008, 15:07
by rinoa79
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

Re: How Celestia calculates speed?

Posted: 03.10.2008, 10:27
by SU(3)xSU(2)xU(1)
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

Re: How Celestia calculates speed?

Posted: 06.10.2008, 19:11
by rinoa79
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.

Re: How Celestia calculates speed?

Posted: 06.10.2008, 21:55
by SU(3)xSU(2)xU(1)
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

Re: How Celestia calculates speed?

Posted: 07.10.2008, 07:49
by rinoa79
[/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.

Re: How Celestia calculates speed?

Posted: 09.10.2008, 16:03
by rinoa79
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

Re: How Celestia calculates speed?

Posted: 09.10.2008, 16:44
by SU(3)xSU(2)xU(1)
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

Re: How Celestia calculates speed?

Posted: 09.10.2008, 16:56
by rinoa79
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.