Here’s a program that unwraps an icosphere, converting the x,y,z points to latitude and longitude and ploting the points. Run in landscape mode and change the level numbers for the icospheres 0 thru 5. The number of point are shown for each run. There’s no real purpose for this program, I just found it interesting to see the patterns. Levels 0 thru 5 will draw an icosphere, but anything above 5 will only show the points, and take awhile to run. I’m not sure if the values above 5 are correct.
displayMode(FULLSCREEN)
function setup()
level=1 -- change level 0 thru 5
assert(craft, "Please include Craft as a dependency")
assert(OrbitViewer, "Please include Cameras (not Camera) as a dependency")
scene = craft.scene()
v=scene.camera:add(OrbitViewer, vec3(0,0,0), 500, 0, 600)
llTab={}
fill(0,255,0)
createSphere()
cnt=sph.model.indexCount//6+2
end
function draw()
update(DeltaTime)
scene:draw()
for a,b in pairs(llTab) do
point(b.x*2.6+500,b.y*1.5+560)
end
text("Number of points "..cnt,WIDTH/2,HEIGHT-20)
end
function update(dt)
scene:update(dt)
end
function createSphere()
sph=scene:entity()
sph.position=vec3(5,-80,0)
sph.model = craft.model.icosphere(60,level,1)
sph.material = craft.material("Materials:Standard")
for a,b in pairs(sph.model.colors) do
sph.model:color(a,math.random(255),math.random(255),math.random(255),255)
end
-- convert x,y,z coords to latitude and longitude
for a,b in pairs(sph.model.positions) do
local c=b:normalize()
local r=math.sqrt(c.x*c.x+c.y*c.y+c.z*c.z)
local lat=math.deg(math.asin(c.z))
local lon=math.deg(math.atan2(c.y,c.x))
table.insert(llTab,vec2(lon,lat))
end
end