super_ellipse.lua
NAME
super_ellipse
FUNCTION
super_ellipse(slices, rx, ry, p)
NOTES
Creates 2D super ellipse line.
Based on the equations
x = rx * cos(phi)^p
y = ry * sin(phi)^p
of Paul Bourke' home page (http://astronomy.swin.edu.au/~pbourke/surfaces/mobius/).
Where 0 <= phi <= pi / 2 and 0 < p < infinite.
Example:
require("plot_simple")
plot = plot_simple.new()
plot:add_static(zeGrf.new("light"))
require("super_ellipse")
xyz, nor = super_ellipse(36, 100, 100, .5)
line = zeGrf.new("line")
line:set{type = "strip", vertex = xyz, vertex_normal = nor, color = {0, .5, .5, 1}}
plot:add(line)
plot:animate()
NPUTS
slices - slices between 0 and pi/2
rx - size parameter in x-direction
ry - size parameter in y-direction
p - shape parameter
OUTPUTS
Two zeArray objects containing coordinates and normals.
The z-component is zero.
SOURCE
require("curve_generator")
function super_ellipse(slices, rx, ry, p)
assert(slices >= 16)
assert(rx > 0)
assert(ry > 0)
assert(p > 0)
local function cfunc(t)
return rx * math.cos(t)^p, ry * math.sin(t)^p
end
local function nfunc(t)
local cos, sin = math.cos(t), math.sin(t)
local x, y, d
x = ry * cos * sin^p / sin
y = rx * sin * cos^p / cos
d = math.sqrt(x * x + y * y)
return x/d, y/d
end
local T = zeUtl.new("double")
T:range(1.e-12, 1.5707963/slices, slices+1)
xyz = curve_generator(T, cfunc)
nor = curve_generator(T, nfunc)
return xyz, nor
end