Question: There is a special way of mapping a cube to a sphere described here:
<http://mathproofs.blogspot.com/2005/07/mapping-cube-to-sphere.html>

It is not your basic "normalize the point and you're done" approach and gives a much more evenly spaced mapping.

I've tried to do the inverse of the mapping going from sphere coords to cube coords and have been unable to come up the working equations. It's a rather complex system of equations with lots of square roots.

Any math geniuses want to take a crack at it?

Here's the equations in c++ code:

```
sx = x * sqrtf(1.0f - y * y * 0.5f - z * z * 0.5f + y * y * z * z / 3.0f);

sy = y * sqrtf(1.0f - z * z * 0.5f - x * x * 0.5f + z * z * x * x / 3.0f);

sz = z * sqrtf(1.0f - x * x * 0.5f - y * y * 0.5f + x * x * y * y / 3.0f);

```

sx,sy,sz are the sphere coords and x,y,z are the cube coords.

Answer: 
Here's one way you can think about it: for a given point P in the sphere, take the segment that starts at the origin, passes through P, and ends at the surface of the cube. Let L be the length of this segment. Now all you need to do is multiply P by L; this is equivalent to mapping ||P|| from the interval [0, 1] to the interval [0, L]. This mapping should be one-to-one - every point in the sphere goes to a unique point in the cube (and points on the surface stay on the surface). Note that this is assuming a unit sphere and cube; the idea should hold elsewhere, you'll just have a few scale factors involved.

I've glossed over the hard part (finding the segment), but this is a standard raycasting problem. There are some links [here](http://realtimerendering.com/intersections.html) that explain how to compute this for an arbitrary ray versus axis-aligned bounding box; you can probably simplify things since your ray starts at the origin and goes to the unit cube. If you need help simplify the equations, let me know and I'll take a stab at it.
It looks like there is a much cleaner solution if you're not afraid of trig and pi, not sure if it's faster/comparable though.

Just take the remaining components after determining the face and do:

```
u = asin ( x ) / half_pi
v = asin ( y ) / half_pi

```

This is an intuitive leap, but [this](https://www.mvps.org/directx/articles/spheremap.htm) seems to back it up ( though not exactly the same topic ), so please correct me if I'm wrong.

I'm too lazy to post an illustration that explains why. :D