/usr/share/celestia/scripts/z-dist.celx is in celestia-common 1.6.1+dfsg-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | -- Title: Show Redshifts of Galaxies
function get_distance(obj_pos, ref_pos)
-- Returns distance Earth-object in Mpc.
distance = ref_pos:distanceto(obj_pos) * km2Mpc
return distance
end
function get_z(distance)
-- Returns redshift z.
-- Hubble constant = 73.2 (km/s)/Mpc, WMAP 3years, best
-- http://map.gsfc.nasa.gov/m_mm/tp_links.html
local H0 = 73.2
local c = 299792.458
z0 = (H0 * distance)/c
z = z0*(1 - z0/4)/(1 - z0/2)^2
-- d <= 2 * c/H0
return z
end
function rgb2hex(r,g,b)
-- Converts color code from RGB to Hex
local hex = string.format("#%.2x%.2x%.2x", r,g,b)
return hex
end
function get_color(z_rel)
-- Returns Hex color code from z_rel
if z_rel > 1 then
z_rel = 1
end
--local green = 255 * (1 - z_rel)/(1 + math.sqrt(z_rel))
local green = 255 * (1 - z_rel)^2
local red = 255
local blue = 255* math.sqrt(green/255)
hex_color = rgb2hex(red, green, blue)
return hex_color
end
function mark_galaxies(sel_pos)
zz = z_max(sel_pos)
for dso in celestia:dsos() do
if dso:type() == "galaxy" then
dso_pos = dso:getposition()
local d = get_distance(dso_pos,sel_pos)
local z_rel = get_z(d)/zz
local hex_color = get_color(z_rel)
dso:mark( hex_color, "disk", 1, 1 )
end
end
end
function z_max(ref_pos)
-- determine maximal redshift in catalog wrto ref_pos
z_old = 0
for dso in celestia:dsos() do
if dso:type() == "galaxy" then
dso_pos = dso:getposition()
local d = get_distance(dso_pos, ref_pos)
local z = get_z(d)
if z > z_old then
z_max = z
z_old = z_max
dsomax = dso
end
end
end
return z_max
end
----------
-- main --
----------
celestia:unmarkall()
celestia:show("markers")
km2Mpc = 1/3.08568025e19
MW = celestia:find("Milky Way")
MW_pos = MW:getposition()
--
-- select and specially mark Milky Way
--
celestia:select(MW)
celestia:mark(MW)
--
-- color encode all other galaxies according to their redshift
-- relative to Milky Way
--
mark_galaxies(MW_pos)
--
-- move observer to a distance of 1000 Mpc from Milky Way
--
observer = celestia:getobserver()
observer:gotodistance(MW, 1000/km2Mpc,5)
sel_old = MW
while true do
sel = celestia:getselection()
--
-- specially mark possible new selection, unmark the old one
--
if sel ~= sel_old then
sel:unmark()
sel_old:unmark()
sel:mark("#00FF00","disk",10,1)
sel_old = sel
end
sel_pos = sel:getposition()
-- obs_pos = observer:getposition()
if sel:type() == "galaxy" then
local d = get_distance(MW_pos,sel_pos)
local z = get_z(d)
celestia:print(sel:name()..": "..string.format("redshift z = %5.3f, distance = %5.2f Mpc", z,d).."\nmax. redshift: "..dsomax:name(),5,-1,-1,0,6)
end
wait(0)
end
|