Module:Ordnance Survey coordinates/sandbox: Difference between revisions

Content deleted Content added
tweak?
atan2 doesn't work and fix other bugs
Line 510:
local phi = deg2rad ( latitude )
local lambda = deg2rad ( longitude )
 
local cosphi = cos ( phi )
local sinphi = sin ( phi )
Line 524 ⟶ 523:
local y1 = ny * cosphi * sinlambda
local z1 = ny * ( 1. - e1 ) * sinphi
 
-- the helmert transformation proper
-- Equation 3, Section 6.2, Ordnance Survey document
Line 531 ⟶ 529:
local y2 = ty + ( rz * x1 + s0 * y1 - rx * z1 )
local z2 = tz + ( -ry *x1 + rx * y1 + s0 * z1 )
 
-- convert cartesian coordinates to latitude and longitude
-- math in Annex B.2, of Ordnance Survey document
Line 538 ⟶ 535:
local e2 = ( aq - b2 * b2 ) / aq
 
lambda = atan ( y2 ,/ x2 )
 
local p2 = sqrt ( x2*x2 + y2*y2 )
phi = atan ( z2 ,/ p2*(1.-e2) )
 
local limit = 1. / b2
Line 550 ⟶ 547:
phi_alt = phi
ny = a2 / sqrt ( 1. - e2 * sin(phi) * sin(phi) )
phi = atan ( (z2 + e2 * ny * sin(phi)) ,/ p2 )
n0 = n0 - 1
until abs ( phi - phi_alt ) <= limit or n0 <= 0
Line 595 ⟶ 592:
local T = pow( tan(lat_rad), 2)
local C = e_prime_sq * pow( cos(lat_rad), 2)
local A = deg2rad( longitude2 -longitude_originlon0GB ) * cos(lat_rad)
local M = find_M( lat_rad )
local M0 = 0.0
if latitude_origin ~= 0 then
M0 = find_M(deg2rad( latitude_originlat0GB ))
end
 
Line 624 ⟶ 621:
local function LatLon2OSGB36( latlon )
local tm = LatLonOrigin2TM(latlon.lat, latlon.lon)
if not tm then return 'TM failure '..tostring(latlon.lat)..' '..tostring(latlon.lon) end
 
-- fix by Roger W Haworth
Line 634 ⟶ 631:
local letters = "ABCDEFGHJKLMNOPQRSTUVWXYZ"
local c1indx1 = mw.ustring.sub(letters,18-floor(grid_y/5)*5+floor(grid_x/5),1)
local c2indx2 = mw.ustring.sub(letters,21-(grid_y%5)*5+grid_x%5,1)
local c1 = mw.ustring.sub(letters,indx1,indx1)
local c2 = mw.ustring.sub(letters,indx2,indx2)
 
local e = mw.ustring.format('%05d', tm.easting%100000)
Line 650 ⟶ 649:
function oscoord.WGS2OSGB(frame)
local args = getArgs(frame)
return args[1]..' '..and args[2]..' '..and oscoord._WGS2OSGB(args[1],args[2]) or ''
end