I need to project a point from a sphere onto a cube that is tangent to the sphere.

Sabudum

New member
Joined
Oct 8, 2018
Messages
2
Hello everyone, i'm new to the forums and also to math apparently, because i'm stuck with a problem that i can't seem to figure out.

What i need to do is take an arbitrary vector position on the surface of a sphere of 1 unit radius, and project that point onto the surface of a cube that envelops the sphere and is tangent to it, of 2x2 unit each side. (That makes the inside of the cube touch the outside of the sphere)

I found an equation that lets you take a point on a circle and project it to a square, and it works just fine:
x = ½ √( 2 + u² - v² + 2u√2 ) - ½ √( 2 + u² - v² - 2u√2 )
y = ½ √( 2 - u² + v² + 2v√2 ) - ½ √( 2 - u² + v² - 2v√2 )

However, it is 2D, and i need it to be 3D, but i don't really know how to make it 3D.

Can anyone help me to make it 3D, or may have another solution that is entirely different or simpler? I'd be much appreciated.
 
I don't know what you mean by "project a vector onto a cube". A vector is "projected" onto a surface, not onto a three dimensional object.
 
My best guess is that you want to take a point on a sphere (identified by its position vector, which is simply a unit vector, and is equivalent to the coordinates of a point on the sphere), and project it from the origin onto the cube circumscribing the sphere, which means onto whichever of 6 planes is closest. That is, you want to find the intersection of the ray from the origin through the point, with one of the planes x=1, x=-1, y=1, y=-1, z=1, and z=-1.

To do this, you can simply find the greatest coordinate of the point to find the appropriate plane, and then multiply the position vector by 1/a, where a is the value of that coordinate. For example, the point (2/3, 1/2, sqrt(11/6)) is on the plane x=1, so we multiply the coordinates by 3/2 to get (1, 3/4, 3/2 sqrt(11/6)).

I haven't examined your formula, but it may do the equivalent work on a plane, but obscuring what it does by combining 6 cases into one. That just makes the work harder.
 
Thanks for all your answers everyone! to clarify what i meant, i wanted to take the direction vector of a point on the surface of the sphere, and project it onto the surface of the cube, which gives me a position on the cube, not just the direction of that position.

As Dr. Peterson stated: "to take a point on a sphere (identified by its position vector, which is simply a unit vector, and is equivalent to the coordinates of a point on the sphere), and project it from the origin onto the cube circumscribing the sphere"

Thanks Dr. Peterson for your suggested solution, i will try it and see the results, it looks like that is exactly what i need.

EDIT: I tried out Dr. Peterson's suggestion and it turns out it works perfectly, i just had to use the absolute value of a, because it was inverting the position if the z value was negative, so the final equation should be: 1 / max[ abs(x) , abs(y) , abs(z) ] * (x,y,z)

I'm truly sorry if i did not made myself clear in the beginning, i'm learning to code in c++ and when programming, positions are stated as vectors, and very often, equations are very complex because a graphics card doesn't understand math very well, anyway, thanks again, and the answer will always be here if anyone finds it useful.

Goodbye.
 
Last edited:
Top