# Thread: Map a cube to a sphere

1. ## Map a cube to a sphere

I have a regular cube of edge length = 2, and a sphere of radius = 1. Each face of the cube has been divided into N*N equal-area squares. How can I compute the projected area of every square on the sphere, so that the area of all the projections sum up to 4*pi.
I came to the following solution but the result does not sum to 4*pi:

1. Denote the area of each square on the cube as: A
2. Denote the length of the line segment connecting the center of the cube with the center of a square on the cube face as: R
3. Then I compute the cosine of the angle between the above line segment with a face normal (ex. if the square lies in +X face, then the angle is between the line segment and the normal of face +X).

so that the projection of the area from the square to the sphere can be computed as:
A * cosine(angle) / R^2
However, the above solution does not sum to 4*pi

For some reason, I can only divide each cube face into a limited number of squares, say 15*15.

2. This is a simple problem. With your cube at the origin subdivide the cube faces and normalize the vertices as if they are vectors, this will produce a unit radius sphere if you are around the origin. Also use the vertices as the normals for shading. Interpolate from the original geometry for a gradual transition.

3. Using a modeler called Lightwave, I've tried to do what you described. Does looking at this figure help out at all? As you can see, the small squares on the cube project to quads of different sizes and shapes on the sphere. This was done by simply normalizing all the vertices on the cube. The results sort of looks like the patch pattern of a soccer ball.

Attachment 1060

4. Thanks a lot. I have never tried Lightwave before. Did you do the projection by directly programming in Lightwave?

5. Originally Posted by Carmine
Using a modeler called Lightwave, I've tried to do what you described. Does looking at this figure help out at all? As you can see, the small squares on the cube project to quads of different sizes and shapes on the sphere. This was done by simply normalizing all the vertices on the cube. The results sort of looks like the patch pattern of a soccer ball.

Attachment 1060
Thanks a lot. I have never tried Lightwave before. Did you do the projection by directly programming in Lightwave?

6. you can just generate subdivided cube yourself in your code and normalize it's vertices.

lightwave just has a function called "spherize", which does exactly what you can see on a screenshot. it requires just a decently subdivided mesh. but to use a lightwave object in your application is whole another story. their file format is hell to parse, it's one of the worst in existence(not mentioning animation files. i know, cause i did that), and all the existing parsers are half-assed. but i guess, you can convert it to collada and parse it with much less pain. but i don't know, how much information about object it will preserve. other modelling tool's also have simillar functions to lightwave's "spherize".

7. Originally Posted by shapeare
Thanks a lot. I have never tried Lightwave before. Did you do the projection by directly programming in Lightwave?
As the other poster mentioned I used a function called 'Spherize' provided by Lightwave. I didn't have to do any programming. I posted this more to help you resolve your surface area problem. Lightwave is fairly expensive software. I wasn't recommending you purchase it to solve your problem. As Dorbie says, it can be done purely in OpenGL. Start by generating a cube with sides subdivided into quads. After you've done that it will become obvious what comes next.

8. Originally Posted by Nowhere-01
... you can convert it to collada and parse it with much less pain .
I'm not familiar with the Collada format. I like obj format which Lightwave exports to. It's fairly easy to parse.

9. Collada is an XML based format for exchanging 3D data. It is more comprehensive than .obj but is more difficult to parse. I have also found that a lot of packages don't export and/or import it correctly.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•