Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 9 of 9

Thread: Map a cube to a sphere

  1. #1
    Intern Contributor
    Join Date
    Jun 2011
    Posts
    90

    Unhappy 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.
    Last edited by shapeare; 06-24-2013 at 07:46 AM.

  2. #2
    Super Moderator OpenGL Guru dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    3,947
    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. #3
    Junior Member Regular Contributor
    Join Date
    Apr 2012
    Location
    Los Angeles
    Posts
    187
    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.

    Click image for larger version. 

Name:	Cube_Sphere.jpg 
Views:	105 
Size:	24.3 KB 
ID:	1060
    Last edited by Carmine; 06-26-2013 at 05:17 PM.

  4. #4
    Intern Contributor
    Join Date
    Jun 2011
    Posts
    90
    Thanks a lot. I have never tried Lightwave before. Did you do the projection by directly programming in Lightwave?

  5. #5
    Intern Contributor
    Join Date
    Jun 2011
    Posts
    90
    Quote Originally Posted by Carmine View Post
    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.

    Click image for larger version. 

Name:	Cube_Sphere.jpg 
Views:	105 
Size:	24.3 KB 
ID:	1060
    Thanks a lot. I have never tried Lightwave before. Did you do the projection by directly programming in Lightwave?

  6. #6
    Member Regular Contributor Nowhere-01's Avatar
    Join Date
    Feb 2011
    Location
    Novosibirsk
    Posts
    251
    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".
    Last edited by Nowhere-01; 06-27-2013 at 12:34 AM.

  7. #7
    Junior Member Regular Contributor
    Join Date
    Apr 2012
    Location
    Los Angeles
    Posts
    187
    Quote Originally Posted by shapeare View Post
    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. #8
    Junior Member Regular Contributor
    Join Date
    Apr 2012
    Location
    Los Angeles
    Posts
    187
    Quote Originally Posted by Nowhere-01 View Post
    ... 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. #9
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    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
  •