View Full Version : Map a cube to a sphere

shapeare

06-24-2013, 06:29 AM

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:

Denote the area of each square on the cube as: A

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

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.

dorbie

06-24-2013, 01:18 PM

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.

Carmine

06-26-2013, 05:09 PM

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.

1060

shapeare

06-27-2013, 12:18 AM

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

shapeare

06-27-2013, 12:19 AM

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.

1060

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

Nowhere-01

06-27-2013, 12:28 AM

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

Carmine

06-27-2013, 10:35 AM

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.

Carmine

06-27-2013, 10:37 AM

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

tonyo_au

06-27-2013, 05:08 PM

Collada (https://collada.org/)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.

Powered by vBulletin® Version 4.2.5 Copyright © 2018 vBulletin Solutions Inc. All rights reserved.