xy2sphere.lua
NAME
xy2sphere
FUNCTION
xy2sphere(lon, lat, rad)
NOTES
Project Longitude and latitude on spheric surface.
INPUTS
lon - number or zeArray object as longitude in degree
lat - number or zeArray object as latitude in degree
rad - radius of the sphere
OUTPUTS
Returns x, y, and z as numbers or zeArray objects depending on inputs.
SOURCE
require("register")
function xy2sphere(lon, lat, rad)
if (type(lon) == "userdata") then
zeMath.deg2rad(lon)
zeMath.deg2rad(lat)
local x, y, z, r = zeUtl.new("double", "double", "double", "double")
lon:copy(x)
lon:copy(y)
lat:copy(z)
lat:copy(r)
zeMath.cos(x)
zeMath.sin(y)
zeMath.sin(z)
zeMath.cos(r)
z:mul(rad)
r:mul(rad)
x:mul(r)
y:mul(r)
return x, y, z
else
lon = lon * 0.017453293
lat = lat * 0.017453293
local z = rad * math.sin(lat)
local r = rad * math.cos(lat)
local x = r * math.cos(lon)
local y = r * math.sin(lon)
return x, y, z
end
end