Jump to content

Module:Sandbox/Jackmcbarn

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Jackmcbarn (talk | contribs) at 02:27, 11 September 2014 (add lambertConformalConic function). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local p = {}

function p.lambertConformalConic(refLat, refLong, stdParallel1, stdParallel2)
	return function(latitude, longitude)
		local n
		if stdParallel1 == stdParallel2 then
			n = math.sin(stdParallel1)
		else
			n = math.log(math.cos(stdParallel1)/math.cos(stdParallel2))/
				math.log(math.tan(0.25*math.pi + 0.5*stdParallel2)/math.tan(0.25*math.pi + 0.5*stdParallel1))
		end
		local f = math.cos(stdParallel1)*math.tan(0.25*math.pi + 0.5*stdParallel1)^n/n
		local rho = f*math.tan(0.25*math.pi + 0.5*latitude)^-n
		local rho0 = f*math.tan(0.25*math.pi + 0.5*refLat)^-n
		return {
			x = rho*math.sin(n*(longitude - refLong)),
			y = rho0 - rho*math.cos(n*(longitude - refLong))
		}
	end
end

function p.main(frame)
	local args, args_mt = { '__pairs was not used' }, {}
	function args_mt.__pairs( t )
		return pairs( { 'success' } )
	end
	return frame:expandTemplate{ title = 'Echo', args = setmetatable( args, args_mt ) }
end

return p