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 NN 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 4pi.
I came to the following solution but the result does not sum to 4*pi:

[ol]
[li]Denote the area of each square on the cube as: A[/li][li]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[/li][li]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).[/li][/ol]
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.

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.

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.

[ATTACH=CONFIG]1060[/ATTACH]

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

[QUOTE=Carmine;1252177]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.

[ATTACH=CONFIG]1060[/ATTACH][/QUOTE]

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

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”.

[QUOTE=shapeare;1252185]Thanks a lot. I have never tried Lightwave before. Did you do the projection by directly programming in Lightwave?[/QUOTE] 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.

[QUOTE=Nowhere-01;1252186]… you can convert it to collada and parse it with much less pain .[/QUOTE] I’m not familiar with the Collada format. I like obj format which Lightwave exports to. It’s fairly easy to parse.

Colladais 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.