Jump to content
• Advertisement

# Map a point on a sphere to a cube

This topic is 3900 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

## Recommended Posts

I have an interesting problem, to make a long story short I need to be able to map any given point (x,y,z) on the surface of a unit sphere to an equivalent point on a unit cube. For example the point {1,1,1}/sqrt(3) on the sphere would map to {1,1,1} on the cube and {1,0,0} on the sphere would be {1,0,0} on the cube. I found some equations online, but they don't seem to work correctly. Anybody know?

#### Share this post

##### Share on other sites
Advertisement
You want to find the intersection of a ray starting from the origin and the 6 planes that define the unit cube. In general, you could find the intersection of a ray and the planes, but since they are the planes of a unit cube the math becomes simpler. The element of the direction vector with the largest magnitude will determine which of the sides of the cube the ray will intersect first (its sign is also important).

For example, given a vector (x,y,z), if the x component has the greatest magnitude and is positive then the ray will first intersect the plane that goes through (1,0,0) with a normal of (1,0,0). The ray can be described as the set of points t*(x,y,z), where t is any positive number. Likewise the plane is the set of points P such that (1,0,0)*P = 1. Substituting the points of the ray into the plane equation gives (1,0,0)*t*(x,y,z) = 1. All the zeros in the unit plane equation make the math really simple, allowing us to reduce this to t*x = 1.

The math works out similiarly for all of the planes. Just determine which component of the vector is the largest, and then compute the absolute value of its reciprocal and divide all components of the vector by that.

#### Share this post

##### Share on other sites
I had done that originally, and that will work for what I need. But what I was looking for was a different equation, a more accurate mapping. Using the method you described I believe will cause distortion. If there are an evenly distributed number of points on the surface of the sphere, when using the method above the points will no longer be evenly distributed along the surface of the cube, the points on the edge of any side of the cube will be spaced further apart than the points at the center of the side of the cube.

#### Share this post

##### Share on other sites
This problem is like trying to project a globe onto a flat map. It's impossible to make a map of a sphere that both preserves shape and area; the best you can do is make a compromise. The projection described in my previous post, which I believe is the one most commonly used in cube mapping for graphics (probably because of its simplicity), is a type of dymaxion projection, which itself uses gnomonic projections for each of the sides. More generally it should be possible to use other types of projections for the sides, dividing the sphere into 6 sections and then projecting each of them onto a square, but there will always be some sort of distortion somewhere.

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
Rutin
36
2. 2
3. 3
4. 4
5. 5
• Advertisement

• 11
• 10
• 13
• 100
• 11
• ### Forum Statistics

• Total Topics
632974
• Total Posts
3009659
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!