#Mapping Sphere to Cube

29 messages · Page 1 of 1 (latest)

hot python
#

(Not in university, for a personal project)
I have a special equation for mapping from a cube to a sphere. It's particularly good for minimizing the distortion near the corners (attached).
However, I also need the inverse mapping. In other words, I need to solve the system of equations for x, y, z (position on a cube) given x', y', z' (position on a sphere). I've heard you're supposed to take 2 equations at a time and eliminate a variable, but I don't know how to do that with these square roots. Any help would be greatly appreciated.
Equation from: https://catlikecoding.com/unity/tutorials/cube-sphere/

delicate martenBOT
#
  1. Wait patiently for a helper to come along.
  2. Once someone helps you, say thank you and close the thread with:
+close
  1. Feel free to nominate the person for helper of the week in #helper-nominations
  2. Do not ping the mods, unless someone is breaking the rules.
  3. If you're happy with the help you got here, and the server overall, you can contribute financially as well:
rancid ridge
hot python
#

Oy vey. I mean I can approximate the solution by computing a look-up-table but... I'd really rather not do that if computing the exact solution is possible and isn't too complex computationally

rancid ridge
#

Hmm... Perhaps it would be easier if we switched to spherical coordinates? Not sure, though.

hot python
#

It might be simpler if I try to solve for just the top of the cube, so z = 1

rancid ridge
#

Oh, that's true!

hot python
#

At least for that I get:

x' = x * sqrt(0.5 - y^2/2 + y^2/3)
y' = y * sqrt(0.5 - x^2^2 + x^2/3)
z' = sqrt(1 - x^2/2 - y^2/2 + x^2*y^2/3)

maybe this helps?
1 = x'^2 + y'^2 + z'^2
#

But I keep getting in the situation where I can't figure out how to further eliminate a variable

rancid ridge
#

Then we have:
X = x√(1/2 - y^2/6)
Y = y√(1/2 - x^2/6)
Squaring and multiplying by 6 produces:
6X^2 = x^2 (3 - y^2)
6Y^2 = y^2 (3 - x^2)
Let's replace the equations by their sum and difference.
6(X^2 + Y^2) = 3x^2 - 2x^2 y^2 + 3y^2
2(X^2 - Y^2) = x^2 - y^2
From the second equation:
x^2 = 2(X^2 - Y^2) + y^2
Substituting into the first, we get:
6(X^2 + Y^2) = (3 - 2y^2)(2(X^2 - Y^2) + y^2) + 3y^2
And this is a quadratic equation in y^2, so the rest shouldn't be a problem.

hot python
#

I multiplied that out to:
0 = 6y^2 - 2y^4 - 12y'^2 - 4y^2x'^2 + 4y^2y'^2 but that doesn't seem like a quadratic 💀

hot python
#

When I try another way I get:
x'^2 = x^2 * (0.5 - 6y'^4 / (x^4 - 6x^2 + 9))
but fml that's got x^4

hard herald
hard herald
hot python
#

I've spent 5 hours on this, please kill me

hard herald
hot python
#

Solve for x, y, & z

hard herald
#

i think

#

y+mx+c

#

x=my+c

#

z = idk

#

that's the best ik

#

im in middle school literally

hot python
rancid ridge
hot python
#

+close