Module:Convert: Difference between revisions

syncing discussed and well-tested changes in sandbox to live (speed_of_sound calculation logic simplification, variable name change)
(update from sandbox per Template talk:Convert#Module version 13)
(syncing discussed and well-tested changes in sandbox to live (speed_of_sound calculation logic simplification, variable name change))
Line 373:
-- Table gives speed of sound in miles per hour at various altitudes:
-- altitude = -17,499 to 302,499 feet
-- mach_table[ascale + 4] = s where
-- ascale = (altitude / 5000) rounded to nearest integer (-3 to 60) incl
-- s = speed of sound (mph) at that altitude
-- LATER: Should calculate result from an interpolation between the next
-- lower and higher altitudes in table, rather than rounding to nearest.
-- From: http://www.aerospaceweb.org/question/atmosphere/q0112.shtml
local mach_table = { -- ascale =
799.5, 787.0, 774.2, 761.207051, -- -3 to 0
748.0, 734.6, 721.0, 707.0, 692.8, 678.3, 663.5, 660.1, 660.1, 660.1, -- 1 to 10
Line 389:
}
altitude = altitude or 0
-- divide altitude and add a fudge factor (complication of 0) before we floor it
local a = (altitude < 0) and -altitude or altitude
-- ensure it is within range [-3..60]
a = floor(a / 5000 + 0.5)
scale = math.max(-3, math.min(60,
if altitude < 0 then
floor(altitude / 5000 + ((altitude < 0) and 0.4998 or 0.5))))
a = -a
return mach_table[ascale + 4] * 0.44704 -- mph converted to m/s
end
if a < -3 then
a = -3
elseif a > 60 then
a = 60
end
return mach_table[a + 4] * 0.44704 -- mph converted to m/s
end
-- END: Code required only for built-in units.
Anonymous user