[Closed] Turning a Sphere into a Plane
Hi, I am looking for a script that will turn a Sphere into a plane. I have found a script that turns a Plane into a Sphere, but can’t found out a way to go the other way. Any help ?? I will post the script I found just in case it helps. Thanks.
fn plane2Sphere plane =(
local minX=plane.min.x,
minY=plane.min.y,
maxX = plane.max.x,
maxY = plane.max.y,
xLen=maxX-minX,
yLen=maxY-minY,
r=yLen/(2*pi)
for i=1 to plane.verts.count do
(
theta = ((plane.verts[i].pos.x - minX)/xLen)*360
phi = ((plane.verts[i].pos.y - minY)/yLen)*180
plane.verts[i].pos.x = r*sin(phi)*cos(theta)
plane.verts[i].pos.y = r*sin(phi)*sin(theta)
plane.verts[i].pos.z = -r*cos(phi)
)
)
plane2Sphere $Plane001
Why you need this?
You can project all verts of the sphere over the imaginary plane that lays on the center of the sphere. This way you will have faces that overlaps. The plane will have “circular” outline.
Also, you can create a plane with the same amount of vertices as the shpere and place it where you want.
Yes, it’s a strange plugin!
Just change all Z coordinates of all verts to a same value (for example).
I think the purpose is to “unwrap” a sphere mesh into a plane (square/rectangle). That would be the inverse effect of the posted code.
Anyway, you can’t turn a default sphere into a plane. The best you could get would be what the default sphere UV mapping does.
For Editable object you cau try this:
Select the sphere and execute.
(
poGetVert = polyop.getVert
poSetVert = polyop.setVert
obj = selection[1]
numVerts = obj.numverts
for v =1 to numVerts do
(
vPos = poGetVert obj v
poSetVert obj v [vPos.x, vPos.y, 0]
)
)
Or simply:
scale $ [1,1,0]
There are other functions for poly like:
makePlanarIn()
makePlanar()
alignToView()
alignToGrid()
But I don’t think this is what the thread is about.
Yeah, I wanted to unwrap the sphere into a plane. I wanted to be able to do this so I can unwrap a globe into a map. I do believe there has got to be a mathmatical way of doing it but thanks for all your answers I will keep searching !!
The problem is not the math but the topology.
A default sphere does have triangles at the poles, and so a perfect plane (square/rectangle) can’t be build.
The following code will picture better what I mean:
(
sphere segs:24 mapcoords:on isselected:on
unwrap = unwrap_uvw()
modpanel.addmodtoselection unwrap ui:on
unwrap.edit()
)
Ok, but I happy to have the sphere a little bit edited. So we can get rid of the triangles on the poles if we apply a Chamfer to them. As I know we need to split one edge so we can make the map. The rest should just be maths ?? I mean, you could be right, and that its impossible but if I can go from a plane to a sphere, I must be able to go backwards right ??
If you will edit the mesh you could build a square out of it of course.
In the example you posted, the sphere has overlapped faces at the poles, so its not a perfect sphere.
If you are planning to use a default sphere, you can take advantage of its uv mapping to build the plane:
(
gc()
delete objects
tmesh = snapshotasmesh (sphere segs:24 mapcoords:on)
verts = for j = 1 to tmesh.numtverts collect (gettvert tmesh j) * [100,100,0]
meshop.setnumverts tmesh verts.count
meshop.setvert tmesh #{1..tmesh.numtverts} verts
for j = 1 to tmesh.numfaces do
(
face = gettvface tmesh j
setface tmesh j face[1] face[2] face[3]
)
mesh mesh:tmesh
delete tmesh
)
If you use the function plane2Sphere() to create the sphere, then you could set it back to a plane with something like this:
-- Test object
converttomesh (plane length:100 width:100 lengthsegs:20 widthsegs:20)
(
fn SphereToPlane obj width length =
(
side = (sqrt obj.numverts) - 1
width /= side
length /= side
v = 1
for y = 0 to side do
(
for x = 0 to side do
(
setvert obj v [x*width, y*length, 0]
v+=1
)
)
update obj
)
SphereToPlane $ 100 100
)
Note that this will work when the plane has an equal number of segment in x and y, but you can modify it to work with different values.