Celx script that displays RA/Dec for observer
-
- Developer
- Posts: 3776
- Joined: 04.02.2005
- With us: 19 years 9 months
Re: Celx script that displays RA/Dec for observer
Would be nice to have this integrated in the default HUD (perhaps next to the FOV)... or, what about adding it to the lua tools? (with a checkbox)
-
Topic authorVincent
- Developer
- Posts: 1356
- Joined: 07.01.2005
- With us: 19 years 10 months
- Location: Nancy, France
Re: Celx script that displays RA/Dec for observer
That's why an option to print UTF-8 chars in celx scripting would be quite useful...Cham wrote:I edited the script to translate it in French, but the UTF8 encoding is really a pain in the butt. Each time I open the file, I'm getting weird characters and have to change them. At least, now it's working.
And what about giving the possibility to switch between different displays: observer's position/selection's position in geocentric/topocentric coordinates... ?ElChristou wrote:Would be nice to have this integrated in the default HUD (perhaps next to the FOV)... or, what about adding it to the lua tools? (with a checkbox)
In the Lua Tools, this could be done via the config file - are there situations which would require displaying both the observer's and the selection's position?.
And for the default HUD, these options could be set via the GUI...
@+
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
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 authorVincent
- Developer
- Posts: 1356
- Joined: 07.01.2005
- With us: 19 years 10 months
- Location: Nancy, France
Re:
Chris,chris wrote:Vincent,
Any idea what's causing this problem? Is it a bug in Lua or the Celestia print functions? It seems unlikely that there's a problem in Lua, yet Celestia routinely uses the degree symbol in strings that don't originate form scripts.
--Chris
Displaying UTF-8 chars, like the degree symbol, works correctly in cel scripting
using their hexadecimal code, e.g., "\u00B0" for the degree symbol:
Code: Select all
{
print { origin "left" row 1 column 1 duration 6 text "\u00B0" }
wait { duration 6 }
}
But this doesn't work in celx scripts. The following celx command displays 'u00B0'
Code: Select all
celestia:print("\u00B0")
I also tried with:
Code: Select all
celestia:print("\\u00B0")
but it doesn't work either.
One reason for this problem might be that '\' is used as escape sequence in Lua...
@+
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
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
Re: Celx script that displays RA/Dec for observer
I'm interested in modifying this script to display RA and DEC of the *observed* direction. I'm new to celestia scripting, could someone give me a hint in order to do it?
edit:
I changed
for
I assume I'm doing something very wrong, since I point to Sirius (Right ascension 06h 45m 08.9173s Declination ?16° 42? 58.017'' ) and I get RA 6h 56m 20s and dec -39d 36' 19''.
edit:
I changed
Code: Select all
local rot = earth:getposition():orientationto(obs:getposition(), LOOK) * base_rot
for
Code: Select all
local rot = obs:getorientation()
I assume I'm doing something very wrong, since I point to Sirius (Right ascension 06h 45m 08.9173s Declination ?16° 42? 58.017'' ) and I get RA 6h 56m 20s and dec -39d 36' 19''.
-
Topic authorVincent
- Developer
- Posts: 1356
- Joined: 07.01.2005
- With us: 19 years 10 months
- Location: Nancy, France
Re: Celx script that displays RA/Dec for observer
You're on the right track. The following code should do what you want:Machete wrote:I'm interested in modifying this script to display RA and DEC of the *observed* direction. I'm new to celestia scripting, could someone give me a hint in order to do it?
edit:
I changedCode: Select all
local rot = earth:getposition():orientationto(obs:getposition(), LOOK) * base_rot
forCode: Select all
local rot = obs:getorientation()
I assume I'm doing something very wrong, since I point to Sirius (Right ascension 06h 45m 08.9173s Declination ?16° 42? 58.017'' ) and I get RA 6h 56m 20s and dec -39d 36' 19''.
Code: Select all
local base_rot = celestia:newrotation(celestia:newvector(1, 0, 0), -J2000Obliquity)
local rot = obs:getorientation() * base_rot
One important thing to keep in mind is that you'll get correct values for RA/Dec exclusively when the observer is in the neighbourhood of the Earth.
@+
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
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
Re: Celx script that displays RA/Dec for observer
Thank you, that worked like a charm
Re: Celx script that displays RA/Dec for observer
I'm trying now to display the quaternion of the observed point, like the quaternion a spacecraft would use. I'm a bit confused about the coordinate system here.
From what I understand, "rot" is a rotation from vector LOOK ==(0,0,-1) to the observation vector. How could I get a quaternion that can transform the vector that points to the vernal equinox (RA 0 DEC 0) into the observation vector? I would then use this quaternion to display it, as well as the euler angles generated with it.
These are the "monstruosities" I am currently making with Vincent's script. When I execute this, it looks like the origin for the euler angles is in 18h, 0 degrees.
From what I understand, "rot" is a rotation from vector LOOK ==(0,0,-1) to the observation vector. How could I get a quaternion that can transform the vector that points to the vernal equinox (RA 0 DEC 0) into the observation vector? I would then use this quaternion to display it, as well as the euler angles generated with it.
These are the "monstruosities" I am currently making with Vincent's script. When I execute this, it looks like the origin for the euler angles is in 18h, 0 degrees.
Code: Select all
-- Return current RA, Dec for observer:
getRADec = function (obs)
local base_rot = celestia:newrotation(celestia:newvector(1, 0, 0), -J2000Obliquity)
local rot = obs:getorientation() * base_rot
local look = rot:transform(LOOK):normalize()
local r, theta, phi = xyz2rtp(look.x, look.z, look.y)
local phi = math.mod(720 - math.deg(phi), 360)
local theta = math.deg(theta)
if theta > 0 then
theta = 90 - theta
else
theta = (-90 - theta)
end
return phi, theta, rot, look.x, look.y, look.z
end
quat2euler = function(qtrn)
local qw = qtrn.w
local qx = qtrn.x
local qy = qtrn.y
local qz = qtrn.z
local phi = math.atan (2*(qy*qw+qx*qz)/(1-2*(qy^2*qz^2)))
local theta= math.asin(2*(qx*qw-qz*qw))
local psi= math.atan2(2*(qx*qw+qy*qz),(1-2*(qx^2+qz^2)))
return phi, theta, psi
end
while true do
obs = celestia:getobserver()
obsR = getR(obs)
obsRA, obsDec, quat, xobs, yobs, zobs = getRADec(obs)
roll, pitch, yaw = quat2euler(quat)
celestia:print(obsR..' '..obsRA..' '..obsDec)
if obsR >= 0 then
-- Display geocentric coordinates for observer:
obsRStr = km2Unit(obsR)
obsRAStr = deg2hms(obsRA)
obsDecStr = deg2dms(obsDec)
celestia:print("\nRA: "..obsRAStr.."\nDec: "..obsDecStr.."\nq0: "..quat.w.."\nq1: "..quat.x.."\nq2: "..quat.y.."\nq3: "..quat.z.."\nroll: "..roll.."\npitch: "..pitch.."\nyaw: "..yaw.."\nx: "..xobs.."\ny: "..yobs.."\nz: "..zobs, 1, -1, -1, 1, 20)
end
wait(0)
end
Re: Celx script that displays RA/Dec for observer
Nevermind, I finally found a way to do it, rotating "rot" 90 degrees around y. Vincent, do you have a last name you can send by private message? I'm using this script in my thesis and I want to give you credit
In case anyone cares (sorry for the crappy coding):
In case anyone cares (sorry for the crappy coding):
Code: Select all
-- Title: Display current RA/Dec and attitude information for the center of the FOV
KM_PER_LY = 9460730472580.8
KM_PER_AU = 149597870.7
PI = math.pi
degToRad = PI / 180;
J2000Obliquity = 23.4392911 * degToRad
fov=math.rad(21.534638888888890);
LOOK = celestia:newvector(0, 0, -1)
earth = celestia:find("Sol/Earth")
-- Convert coordinates from cartesian to polar:
xyz2rtp = function (x, y, z)
local r = math.sqrt(x * x + y * y + z * z)
local phi = math.atan2(y, x)
local theta = math.atan2(math.sqrt(x * x + y * y), z)
return r, theta, phi
end
-- Return current distance of observer from Earth:
getR = function (obs)
return earth:getposition():distanceto(obs:getposition())
end
-- Return current RA, Dec for observer:
getRADec = function (obs)
local base_rot = celestia:newrotation(celestia:newvector(1, 0, 0), -J2000Obliquity)
local startracker_rot = celestia:newrotation(celestia:newvector(0, 1, 0), -1.5708)
local rot = obs:getorientation() * base_rot
local attitude_rot = rot * startracker_rot
local look = rot:transform(LOOK):normalize()
local r, theta, phi = xyz2rtp(look.x, look.z, look.y)
local phi = math.mod(720 - math.deg(phi), 360)
local theta = math.deg(theta)
if theta > 0 then
theta = 90 - theta
else
theta = (-90 - theta)
end
return phi, theta, attitude_rot, look.x, look.y, look.z
end
km2Unit =
function(km)
local sign, value, units
if km < 0 then sign = -1 else sign = 1 end
km = math.abs(km)
if km > 1e12 then
value = km / KM_PER_LY
units = "ly"
elseif km >= 1e8 then
value = km/KM_PER_AU
units = "AU"
else
value = km
units = "km"
end;
return string.format("%.2f", sign * value).." "..units
end
deg2dms = function(deg)
local a = math.abs(deg)
local d = math.floor(a)
local r = (a - d) * 60
local m = math.floor(r)
local s = (r - m) * 60
if deg < 0 then d = -d end
return string.format("%0.0fd %02.0f' %2.0f''",d,m,s)
end
deg2hms = function(deg)
local a = math.abs(deg / 15)
local d = math.floor(a)
local r = (a - d) * 60
local m = math.floor(r)
local s = (r - m) * 60
return string.format("%0.0fh %02.0fm %2.0fs", d, m, s)
end
quat2euler = function(qtrn)
local q4 = qtrn.w
local q2 = -qtrn.x
local q3 = qtrn.y
local q1 = qtrn.z
local yaw = math.atan2 (2*(q1*q2+q4*q3),((q4^2 + q1^2 - q2^2- q3^2)))
local pitch= math.asin(-2*(q1*q3-q4*q2))
local roll= math.atan2(2*(q4*q1+q2*q3),(q4^2 - q1^2 - q2^2+ q3^2))
yawdeg = yaw/degToRad
pitchdeg = pitch/degToRad
rolldeg = roll/degToRad
return yawdeg, pitchdeg, rolldeg
end
while true do
obs = celestia:getobserver()
obs:setfov(fov)
obsR = getR(obs)
obsRA, obsDec, quat, xobs, yobs, zobs = getRADec(obs)
yaw, pitch, roll = quat2euler(quat)
celestia:print(obsR..' '..obsRA..' '..obsDec)
if obsR >= 0 then
-- Display geocentric coordinates for observer:
obsRStr = km2Unit(obsR)
obsRAStr = deg2hms(obsRA)
obsDecStr = deg2dms(obsDec)
celestia:print("\nRA: "..obsRAStr.."\nDec: "..obsDecStr.."\nq4: "..quat.w.."\nq1: "..quat.z.."\nq2: "..-quat.x.."\nq3: "..quat.y.."\nRoll: "..roll.."\nPitch: "..pitch.."\nYaw: "..yaw, 1, -1, -1, 1, 12)
--celestia:print("\nRA: "..obsRAStr.."\nDec: "..obsDecStr.."\nq4: "..quat.w.."\nq1: "..quat.z.."\nq2: "..-quat.x.."\nq3: "..quat.y.."\nRoll: "..roll.."\nPitch: "..pitch.."\nYaw: "..yaw.."\nx: "..xobs.."\ny: "..yobs.."\nz: "..zobs, 1, -1, -1, 1, 20)
--celestia:print("\nRoll: "..roll.."\nPitch: "..pitch.."\nYaw: "..yaw, 1, 1, -1, 1, 8)
end
wait(0)
end
-
- Posts: 7
- Joined: 20.02.2009
- With us: 15 years 9 months
Re: Celx script that displays RA/Dec for observer
Hi.
I have never do a script for celestia. Do you have a tutorial or a manual for the LUA language?
Anyway, I can't download that script. It gives me the 404 advice.
thanks.
mike
I have never do a script for celestia. Do you have a tutorial or a manual for the LUA language?
Anyway, I can't download that script. It gives me the 404 advice.
thanks.
mike
-
Topic authorVincent
- Developer
- Posts: 1356
- Joined: 07.01.2005
- With us: 19 years 10 months
- Location: Nancy, France
Re: Celx script that displays RA/Dec for observer
mike,
http://en.wikibooks.org/wiki/Celestia/C ... ua_Methods
http://vincent.giangiulio.perso.sfr.fr/ ... A_Dec.celx
A tutorial for Celx/lua scripting is available on the Celestia Wiki:starcreator wrote:I have never do a script for celestia. Do you have a tutorial or a manual for the LUA language?
http://en.wikibooks.org/wiki/Celestia/C ... ua_Methods
I've moved to another ftp host. The new link is:starcreator wrote:Anyway, I can't download that script. It gives me the 404 advice.
http://vincent.giangiulio.perso.sfr.fr/ ... A_Dec.celx
@+
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
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
Re: Celx script that displays RA/Dec for observer
Mike,
Another place to look is here on the forum, in the topic titled "A Preliminary Scripting FAQ". It's at the top of the Celestia Scripting Forum. It includes links to CEL and CELX examples and documentation.
Another place to look is here on the forum, in the topic titled "A Preliminary Scripting FAQ". It's at the top of the Celestia Scripting Forum. It includes links to CEL and CELX examples and documentation.
Selden