# intersection between a line and a sphere

I have a plane sphere inscribed in a cube like in the image below.

Both the sphere and the the cube are centered at the origin.

The cube's edge has a unit length (so one edge of the cube is (0.5,0.5,0.5)

Take a point A(x,y,z) situated on one of the faces of the cube. Take the viewing ray be the line OA (O is the origin)

what is the equation of the point S, where S is the intersection between the line OA and the sphere?

So as you guessed I am interested in projecting the sphere on the cube

-

The equation of the sphere is $$x^2+y^2+z^2={1\over 4}.$$

Pick a point $(.5,b,c)$ on the "right and forward face" of the cube.

The parametric equation of the line passing through this point is $$\tag{2}x=. 5 t , y= b t, z=c t$$

Now substitute the $x$, $y$, and $z$ values of the above into the equation for the sphere: $${1\over4} t^2 +b^2 t^2 + c^2 t^2={1\over 4}.$$

Solve the above equation for $t$. Taking the positive solution, and substituting this value into (2) will give you the point on the sphere (the other solution gives the point in "the back").

You can use a similar method for points on the other faces of the cube.

-

Well, since the sphere has radius $1/2$, the intersection between $OA$ and the sphere is just $$A^\prime \left(\frac{x}{2\sqrt{x^2+y^2+z^2}},\frac{y}{2\sqrt{x^2+y^2+z^2}},\frac{y}{2\sqrt{x^2+y^2+z^2}}\right)$$

because $O,A,A^\prime$ are collinear and $OA^\prime=1/2$.

-

Simply normalize the vector $\vec{OA}$ so it gets length equal to the radius of the sphere ($1/2$, in your case). That's how you get the expressions in Beni Bogosel's answer.

-