don wrote:Toti wrote:On coordinate systems: ... but the good thing is that Celestia does all the job for you, so you don't need any knowledge on this.
Really? In Cel, you need to specify 3-value vectors, XYZ rot, angle, base, offset, axis, etc., for commands such as goto, gotoloc, gotolonglat, move, orbit, rotate, setorientation, and setposition. In other words, you can't simply "center" an object and then apply thrust, like you can in the keyboard navigation mode.
For example, trying to get the camera to move in a straight line, towards the center of the screen, has been a futile attempt of many folks -- in both, Cel and Celx.
I think that I haven't explained myself very well...sorry. I was referring to the fact that you don't need to pre calculate and enter a 4x4 matrix (or whatever math device is implied) to do a coordinate system conversion. Of course that you will need a more or less defined idea on how the coordinate systems work (at least at interface level)
A very brief explanation of coordinate systems:
You are walking on the street. Somebody asks you where is certain building. Some possible answers are:
a) 'Two blocks ahead, turn to the left and do two more'
b) '48.8632 S 2.332 E'
c) 'r=28 kly. RA=17:45.7 deg. DE=-28:56 deg.'
All of them are correct (let's assume they are). But you choose the first one. Why? Because it is the most appropriate: it's understandable, short, simple and effective. What your brain is doing is a surprisingly clever thing: it's choosing the best
coordinate system for the occasion.
In an almost subconcious way, you are making some suppositions:
1] This floor tile (where I am standing) is the center of the universe
2]
Up is above my head,
forward is along this street in the direction of traffic, and the street that crosses this one at right angle gives me the remaining direction.
3] The unit of distance is 'a block'
That is in fact the soul of coordinate systems:
1] where is its center placed (the mathematicians call it 'origin of coordinates')
2] how are the three coordinates oriented in space? That is: where is 'up'?, which direction can I call 'ahead'?, etc.
3] in which units can I measure things?
In your room, look at the corner where two walls meet each other and the floor.
There are three ridges that join together in a central point (the origin of coordinates). You can think of this as a natural coordinate system. Let's name each coordinate: the vertical ridge with a Y, and the other two with an X and a Z.
Now you can say, for example: the geometrical center of my computer is 3 meters in the X direction, 2 meters in the Z direction and 1.5 meters in the Y direction
from the origin of coordinates. In fact, you can measure the whole room's content (and the universe) using this coordinate system.
But you may find more comfortable to use another system, like your computer CRT display: the new origin of coordinates would be in the top left point of the screen, the X would be horizontal, the Y vertical (both parallel to the surface), and the Z would be perpendicular to the display's glass cover.
Now you might say: let's change to this newer coordinate system: it's closer to me and more intuitive. You'd start measuring all things in the room in relation to the new system (let's suppose this is important for you
), as you did before with the older one... but you don't have to: you only need to measure the position of the new system in relation to the older one (or vice versa), and then, using some linear algebra, you can compute all objects positions in relation to the new system, without need of additional work!
In short terms, coordinate systems are
transformable: you can change from one to another, when you think that it will make your work easier.
We do this all the time: in the initial example, choosing the referred system allows us to forget about Earth trajectory (polar measuring from the galaxy's center (answer c) would not achieve this: Earth's own motion would leave this spatial point behind very soon). It also allows us to forget about the fact that our planet is of course an spheroid, so technicaly speaking, 'ahead' wouldn't be signalling a surface point, but a 'floating on air' one, etc.
In fact, one of the main goals of linear algebra is to find the coordinate system where that seemingly impossible to resolve math problem turns to be absurdly trivial...
To illustrate a little bit the topic, here is a script that rotates the viewer around the Earth. It's a small modification of Harald Schmidt's Around the Earth, with added comments.
It works in universal coordinates.
Code: Select all
--******************************************************
--******************************************************
-- This script is a modification of Harald Schmidt's
-- "Around the Earth"
--
--
--******************************************************
--******************************************************
--************************************************
--UCS = Universal coordinate system
--************************************************
function around(body, pos, r)
-- this function puts the viewer in 'pos' of body. All is done in UCS:
-- this two equations look rather complicated, but they are only a 2D polar-cartesian conversion,
-- that is, given a (radius,angle) = (r,pos), convert it to (x,y) values. They are a "classic":
local x = r * math.cos(math.rad(pos))
local z = r * math.sin(math.rad(pos))
-- keep the up pointing coordinate on the UCS "horizontal" plane:
local y = 0
-- let's create a vector with the above coordinates. We create a vector because they don't need to be
-- that precise (they are pretty small coordinates, with lenght = r at most):
local offset = celestia:newvector(x,y,z)
-- obtain a vector that is the center of 'body' in UCS. This is a 'position' vector, so it is very precise. Why is this?
-- Because universal coordinate system places its center at about 200 AU from sol. If we do not assure enough precision,
-- our 'rel_pos' would not be placed on 'body' but a few thousand km. from it.
local rel_pos = body:getposition ()
-- viewer's position: let's go to center of body and then go to offset (that is what a vector addition does, really).
-- This adds a 'common vector' to a 'position vector', so the maximun precision is retained. We want that, because we
-- want to place the viewer exactly where it's needed (and not a few thousand km. around)
local rel_pos2 = rel_pos + offset
-- let's place the observer there:
local obs = celestia:getobserver()
obs:setposition (rel_pos2)
-- look at earth center with upvector as "ceiling". This is complex... close your hand. Extend your thumb.
-- Then extend the first finger, and point it to this -> x. (Keep the angle between both fingers fixed.)
-- This behaves like the viewer: your thumb is the 'up' axis. Your first finger is the viewer's 'look_at' axis.
-- When you point it to the 'x', you are transforming the 'up' vector (your thumb moves with your hand),
-- but it doesn't matter, because you have already defined where it is in relation with the rest of your hand.
-- I believe that Celestia does this same thing that you have done with your hand: First creates an "abstract" viewer,
-- then defines where is 'up' and last, moves/rotates the viewer to point its "camera" to the selected body.
-- The 'up' vector signals the viewer's "ceiling" BEFORE Celestia rotates it in order to look at some place.
obs:lookat (rel_pos, upvector)
-- print the viewer's position (in UCS):
celestia:flash("Viewer pos.: " .. rel_pos2.x .. " " .. rel_pos2.y .. " " .. rel_pos2.z , 1)
-- return control to Celestia for a moment (to refresh screen, etc.):
wait(0.0)
end
--************************************************
-- Now call the function
--************************************************
-- define which direction we should call it 'up'.
-- since this is only a rough direction, we can use a 'common vector'. We don't need precision here:
upvector = celestia:newvector (0,1,0)
-- select body:
celBody = celestia:find("Sol/Earth")
-- get its position (remember, since it's a body position relative to a center of coordinates 200 AU far from us,
-- we will need precision here):
zeropos = celBody:getposition()
-- our orbit will take only 60 seconds:
t0 = 0
t1 = 60
-- and we will complete one orbit:
rot_speed = 360 / t1
-- let's fix the viewer's distance to the body's center:
R = 0.005
-- loop for 60 seconds:
while t0 < t1 do
t0 = celestia:getscripttime()
-- this will be the longitude that we will pass to the function.
-- It's in function of time, like many parameter trajectories like:
a = rot_speed * t0 * 5
-- call the function:
around(celBody, a, R)
end
Run it. What do you notice? We wanted to rotate around Earth, and we did it: our viewer now orbits Earth. But there is a small "problem": Earth is tilted, because we are rotating roughly on an UCS "horizontal" plane (we fixed y = 0, and we never changed the default coordinate system: 'universal').
I said
roughly horizontal because Earth is moving, and the plane of this movement (the ecliptic plane) is not parallel to the UCS horizontal plane. Hence the need for an "ecliptic" coordinate system. So Earth is going slightly "down" in its movement with respect to the UCS horizontal plane. (you can clearly see this in the middle coordinate value that is printed by the script). If Earth was still, or if the ecliptic plane was parallel to the UCS horizontal one, this value would be constant.
But you can forget about this details (for now).
What happens if we want to rotate on Earth's equator plane? We could try doing some trigonometrics in order to find a function that could replace the y = 0 line. A properly derived function will give an up and down movement to the viewer, making it follow the equatorial plane.
But there is another way to do it, and it is much simpler: we can change the coordinate system, so:
1] our origin will be at Earth's center.
2] our system will be properly oriented as Earth is: the new 'up' (y coordinate) won't be "vertical", but tilted (following the N-S earth's line), and the x and z coordinates will be on the equatorial plane, pointing 90 degrees apart.
Now mathematical description of the y coordinate becomes easier: where is the equator plane? At y=0 (remeber that in UCS y=0 wasn't the equatorial plane). On this new coordinate system, the fact that the planet is inclined isn't important at all, because the system is inclined
with the planet. We have eliminated the importance of tilt, and made a fairly complex problem a lot easier.
I will add this new script on another post.
Bye