A script request
-
Topic authorReiko
- Posts: 1119
- Joined: 05.10.2006
- Age: 41
- With us: 18 years 1 month
- Location: Out there...
A script request
There is a script to give the observer their RA, Dec and distance in space but could somebody possible make one that will give you your coordinates in a format that the Celestia STC files use? That is, if it's not a huge task to make one and if one doesn't already exist.
Re: A script request
Hi Reiko,
if you already have a scrit that gives you the R, Dec and distance you don't need another script.
Just take the values and report them in your *.STC file.
In a stc file, RA and dec are in decimal degrees and distance is in ly.
For example if your RA is has the form "h, min, sec" just convert it in degree with the formula
RA(degree) = (( h * 15 + mn)*60 + sec ) *60)
if you already have a scrit that gives you the R, Dec and distance you don't need another script.
Just take the values and report them in your *.STC file.
In a stc file, RA and dec are in decimal degrees and distance is in ly.
For example if your RA is has the form "h, min, sec" just convert it in degree with the formula
RA(degree) = (( h * 15 + mn)*60 + sec ) *60)
-
Topic authorReiko
- Posts: 1119
- Joined: 05.10.2006
- Age: 41
- With us: 18 years 1 month
- Location: Out there...
Re: A script request
I know how to convert them but would like a script to show my position in those coordinates.
Here is the script I've been using made by Vincent found here. viewtopic.php?f=9&t=12209&hilit=displaying+position
Could it be modified to show your coordinates in the format that the STC files use?
Here is the script I've been using made by Vincent found here. viewtopic.php?f=9&t=12209&hilit=displaying+position
Code: Select all
-- Title: Display current RA/Dec for observer
KM_PER_LY = 9460730472580.8;
KM_PER_AU = 149597870.7;
PI = math.pi
degToRad = PI / 180;
J2000Obliquity = 23.4392911 * degToRad
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)
local d = (earth:getposition():distanceto(obs:getposition()))
return d
end
-- Return current RA, Dec for observer:
getRADec = function (obs)
local base_rot = celestia:newrotation(celestia:newvector(1, 0, 0), -J2000Obliquity)
local rot = earth:getposition():orientationto(obs:getposition(), LOOK) * 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
end
km2Unit =
function(km)
local sign, value, units
--if not (type(km) == "number") then return km end;
if km < 0 then sign = -1 else sign = 1 end;
km = math.abs(km);
if km > 1000000000000 then
value = km / KM_PER_LY
units = "ly";
elseif km >= 100000000 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.0f %02.0f' %04.2f'' (%0.3f)",d,m,s,deg);
return string.format("%0.0f° %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
while true do
obs = celestia:getobserver()
obsR = getR(obs)
obsRA, obsDec = getRADec(obs)
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("Geocentric coordinates for observer:\nR: "..obsRStr.."\nRA: "..obsRAStr.."\nDec: "..obsDecStr, 1, -1, -1, 1, 7);
end
wait(0)
end
Could it be modified to show your coordinates in the format that the STC files use?
Re: A script request
just a little modification to the previous code :
Code: Select all
-- Title: Display current decimal RA/Dec for observer
KM_PER_LY = 9460730472580.8;
KM_PER_AU = 149597870.7;
PI = math.pi
degToRad = PI / 180;
J2000Obliquity = 23.4392911 * degToRad
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)
local d = (earth:getposition():distanceto(obs:getposition()))
return d
end
-- Return current RA, Dec for observer:
getRADec = function (obs)
local base_rot = celestia:newrotation(celestia:newvector(1, 0, 0), -J2000Obliquity)
local rot = earth:getposition():orientationto(obs:getposition(), LOOK) * 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
end
km2Unit =
function(km)
local sign, value, units
--if not (type(km) == "number") then return km end;
if km < 0 then sign = -1 else sign = 1 end;
km = math.abs(km);
value = km / KM_PER_LY
units = "ly";
return string.format("%.5f",sign*value).." "..units;
end
deg2str = function(deg)
return string.format("%0.6f deg", deg);
end
while true do
obs = celestia:getobserver()
obsR = getR(obs)
obsRA, obsDec = getRADec(obs)
celestia:print(obsR..' '..obsRA..' '..obsDec)
if obsR >= 0 then
-- Display geocentric coordinates for observer:
obsRStr = km2Unit(obsR);
obsRAStr = deg2str(obsRA);
obsDecStr = deg2str(obsDec);
celestia:print("Geocentric coordinates for observer:\nR: "..obsRStr.."\nRA: "..obsRAStr.."\nDec: "..obsDecStr, 1, -1, -1, 1, 7);
end
wait(0)
end
-
Topic authorReiko
- Posts: 1119
- Joined: 05.10.2006
- Age: 41
- With us: 18 years 1 month
- Location: Out there...
Re: A script request
YAY!! Thank you!