Modul:Astronomie
Zur Navigation springen
Zur Suche springen
-- Version 1.0.0
local isOk, GetConst = pcall( require, "Modul:Astronomie/GetConst" )
if type( GetConst ) == "table" then
Extern = GetConst.Const()
end
local function signum(x)
if x > 0 then return 1;
elseif x < 0 then return -1;
else return 0; end
end
local function GetAlpha(Rek)
-- make degrees from de-Wiki "hh/mm/ss"
local T={}
local pos;
local part='';
local num = 0;
local str= Rek .."/00/00"
pos = string.find(str,'/') or 0
if #str > 0 and pos > 0 then
part = string.sub(str,1,pos-1);
num = tonumber(part) or 0
table.insert(T, num);
str = string.sub(str,pos+1);
else
num = tonumber(str) or 0
table.insert(T, num);
str ="";
end
pos = string.find(str,'/') or 0
if #str > 0 and pos > 0 then
part = string.sub(str,1,pos-1);
num = tonumber(part) or 0
table.insert(T, num);
str = string.sub(str,pos+1);
else
num = tonumber(str) or 0
table.insert(T, num);
str ="";
end
pos = string.find(str,'/') or 0
if #str > 0 and pos > 0 then
part = string.sub(str,1,pos-1);
num = tonumber(part) or 0
table.insert(T, num);
str = string.sub(str,pos+1);
else
num = tonumber(str) or 0
table.insert(T, num);
str ="";
end
local Alp = 15*(T[1]+T[2]/60+T[3]/3600);
return Alp
end
local function GetDelta(Dek)
-- make degrees from de-Wiki "dv/dd/mm/ss"
local T={}
local pos;
local part='';
local num = 0;
local sgn = 0;
local str= Dek .."/00/00"
if string.sub(str,1,2) == '-/' then
sgn=-1;
str = string.sub(str,3)
elseif string.sub(str,1,2) == '+/' then
sgn=1;
str = string.sub(str,3)
elseif string.sub(str,1,1) == '/' then
sgn=1;
str = string.sub(str,2)
else
sgn=1;
end
pos = string.find(str,'/') or 0
if #str > 0 and pos > 0 then
part = string.sub(str,1,pos-1);
num = tonumber(part) or 0
table.insert(T, num);
str = string.sub(str,pos+1);
else
num = tonumber(str) or 0
table.insert(T, num);
str ="";
end
pos = string.find(str,'/') or 0
if #str > 0 and pos > 0 then
part = string.sub(str,1,pos-1);
num = tonumber(part) or 0
table.insert(T, num);
str = string.sub(str,pos+1);
else
num = tonumber(str) or 0
table.insert(T, num);
str ="";
end
pos = string.find(str,'/') or 0
if #str > 0 and pos > 0 then
part = string.sub(str,1,pos-1);
num = tonumber(part) or 0
table.insert(T, num);
str = string.sub(str,pos+1);
else
num = tonumber(str) or 0
table.insert(T, num);
str ="";
end
local Del = sgn * (T[1]+T[2]/60+T[3]/3600);
return Del
end
local function GetKart(alf,del)
local T = {}
alf = alf * math.pi /180;
del = del * math.pi /180;
T.x = math.cos(alf) * math.cos(del);
T.y = math.sin(alf) * math.cos(del);
T.z = math.sin(del)
return T -- T{ T.x , T.y , T.z}
end
local function Vector_x_Matrix(M,V)
--[=[ Multiplication of 3x3-matrix with 3-Vector
M = {m11,m12,m1, m21,m22,m23, m31,m32,m33)
V = (v1, v2,v3)
calculating:
v1 m11,m12,m13 x'
(v2) * M( m21,m22,m23 ) = R(y')
v3 m31,m32,m33 z'
]=]
local m11 = tonumber(M[1]) or 0
local m12 = tonumber(M[2]) or 0
local m13 = tonumber(M[3]) or 0
local m21 = tonumber(M[4]) or 0
local m22 = tonumber(M[5]) or 0
local m23 = tonumber(M[6]) or 0
local m31 = tonumber(M[7]) or 0
local m32 = tonumber(M[8]) or 0
local m33 = tonumber(M[9]) or 0
local x = tonumber(V[1]) or 0
local y = tonumber(V[2]) or 0
local z = tonumber(V[3]) or 0
local R={}
R.x = x * m11 + y* m12 + z* m13;
R.y = x * m21 + y* m22 + z* m23;
R.z = x * m31 + y* m32 + z* m33;
return R;
end
local function GetEquat(T)
local x = T.x or 0;
local y = T.y or 0;
local z = T.z or 0;
local hypot = math.sqrt(x*x+y*y)
local alf = 0
local del = 0
if hypot ~= 0 then
alf = signum(y) * x / hypot;
else
alf = 0; -- Ein Himmelspol; undefiniert = Null
end
alf = alf / math.pi *180;
del = math.asin(z) or 0;
del = del / math.pi *180;
return alf, del
end
local function J2000toB1875(alfJ,delJ)
-- alf = rect. in degrees
-- del = decl. in degrees
local T = {0.999535925, 0.027933851, 0.012146003,
-0.027935279, 0.999609760, -0.000170004,
-0.012147193, -0.000169297, 0.999926220 }
local J2000 = GetKart(alfJ,delJ);
local B1875 = Vector_x_Matrix(T,J2000)
local alfB, delB = GetEquat(B1875)
return alfB, delB
end
local Ast = {}
-- GetRek: Converting right ascension from format "hh/mm/ss" to decimal degrees
function Ast.GetRek(frame)
local Data = frame.args[1] or '';
local Alpha = GetAlpha(Data)
return Alpha
end
-- GetDek: Converting declination from format "v/dd/mm/ss" to decimal degrees
function Ast.GetDek(frame)
local Data = frame.args[1] or '';
local Delta = GetDelta(Data)
return Delta
end
-- GetConstellation: Getting the Constellation, where a given point belongs to.
-- yet not complete!
function Ast.GetConstellation(frame)
local RA = frame.args(1) or "";
local DE = frame.args(2) or "";
local Epoch = frame.args(3) or "J2000";
Epoch = string.upper(Epoch);
local pos = string.find(RA,'/') or 0; -- Slash -> deWiki-Notation
local Iswiki = pos > 0;
local alf=0;
local del=0;
local alfB=0;
local delB=0;
if IsWiki then
alf = GetAlpha(RA)
del = GetDelta(DE)
else
alf = tonumber(RA) or 0;
del = tonumber(DE) or 0;
end
if Epoch == 'J2000' then
alfB, delB = J2000toB1875(alf,del);
else
alfB = alf;
delB = del;
end
-- embedding
-- local Result =
end