Create a frame of reference

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

Create a frame of reference

Post #1by rinoa79 » 19.10.2008, 23:55

Hi folks,
please, can someone tells me how to create a frame of reference like J2000 equator (Earth equator at epoch J2000 as the fundamental plane. The x-axis points along the J2000 vernal equinox, the z-axis is the mean north pole, and the y-axis completes the right-handed system) but centered in Earth?
Thanks in advance,
Mary

Avatar
selden
Developer
Posts: 10192
Joined: 04.09.2002
With us: 22 years 3 months
Location: NY, USA

Re: Create a frame of reference

Post #2by selden » 20.10.2008, 01:07

What do you mean by "create a frame of reference"?
Exactly what are you trying to do?

Have you read the related sections in the Celestia WikiBook?

http://en.wikibooks.org/wiki/Celestia#C ... g_Celestia
Selden

Topic author
rinoa79
Posts: 42
Joined: 20.11.2007
Age: 45
With us: 17 years
Location: Milan, Italy

Re: Create a frame of reference

Post #3by rinoa79 » 20.10.2008, 01:26

selden wrote:What do you mean by "create a frame of reference"?
Exactly what are you trying to do?

Have you read the related sections in the Celestia WikiBook?

http://en.wikibooks.org/wiki/Celestia#C ... g_Celestia

I maked this script:

Code: Select all

while true do

ti = celestia:getscripttime()

terra = celestia:find("Sol/Earth")
sat = celestia:find("Sol/Earth/hubble")

-- crea un sistema di coordinate geocentriche
sist_geoc_cart = celestia:newframe("equatorial",terra)

-- posizioni in coordinate universali
planet = terra:getposition()
satellite = sat:getposition()

-- posizioni in coordinate geocentriche
planet_geo = sist_geoc_cart:to(planet)
satellite_geo = sist_geoc_cart:to(satellite)

x = satellite_geo.x*9.461*10^6
y = satellite_geo.y*9.461*10^6
z = -satellite_geo.z*9.461*10^6

RA = math.deg(math.mod(math.atan2(z,x),2*math.pi))
DEC = math.deg(math.atan2(y,math.sqrt(x^2+z^2)))
r = math.sqrt(x^2+y^2+z^2)

a = 6378.145
b = 6356.785

e = math.sqrt(1-(b/a)^2)
ep = math.sqrt((a/b)^2-1)
p = math.sqrt(x^2+z^2)
phi = math.atan2(a*y,b*p)
long = math.atan2(z,x)
lat = math.atan2(y+ep^2*b*(math.sin(phi))^3,p-e^2*a*(math.cos(phi))^3)
N = a/math.sqrt(1-e^2*(math.sin(lat))^2)
alt = p/math.cos(lat)-N

if math.abs(x)<0.001 and math.abs(z)<0.001 then
   alt = math.abs(y)-b
end

long = math.deg(math.mod(long,2*math.pi))
lat = math.deg(lat)

scritta = "x,y,z:".."   "..x.."   "..y.."   "..z.."\n".."lat,long,h:".." "..lat.."   "..long.."   "..alt.."\n".."RA,DEC,raggio:".."   "..RA.."   "..DEC.."   "..r
celestia:print(scritta,50.0)
wait(1.0)

end

it creates a geocentric coordinate system and calculates the coordinates:
- cartesian
- RA, DEC, r
- latitude, longitude, h
But there is something wrong!
I supposed that geocentric coordinates system hasn't the axes toward orientations that they must have (The x-axis points along the J2000 vernal equinox, the z-axis is the mean north pole, and the y-axis completes the right-handed system)
Probably I'm making some mistake.

Avatar
selden
Developer
Posts: 10192
Joined: 04.09.2002
With us: 22 years 3 months
Location: NY, USA

Re: Create a frame of reference

Post #4by selden » 20.10.2008, 16:51

I always get confused when translating between astronomical coordinates and the xyz coordinates that Celestia uses internally.

The right-mouse-button popup-menu in Celestia v1.6 includes the menu item Reference Vectors / Show Body Axes. They may help some.
Selden

chris
Site Admin
Posts: 4211
Joined: 28.01.2002
With us: 22 years 10 months
Location: Seattle, Washington, USA

Re: Create a frame of reference

Post #5by chris » 22.10.2008, 00:18

Please see this thread, which should clear up some of the confusion about coordinate systems:

viewtopic.php?f=9&t=13110

I've also updated the Celx scripting guide in the Celestia WikiBook with some extra information:

http://en.wikibooks.org/wiki/Celestia/C ... etposition

I want to create a new section of the Celestia WikiBook called the 'Celx Cookbook'. This will be full of well-documented implementations of useful functions.

--Chris


Return to “Scripting”