I am creating an infinite object scroller for a 3D game and need to find the opposite point on a sphere using direction.
If you look at the image above, I have point A as a Vector3 (x, y, z) and direction C as a Vector (x, y, z) and I need to find the point B.
The sphere has a radius of 500 and lies at an origin of 0,0,0
Can someone please give me the equation or point to a reference somewhere? thanks.
The point ${\bf B}$ is the reflection of the point ${\bf A}$ through the plane through the origin orthogonal to (the nonzero) vector ${\bf C}$, so the point ${\bf B}$ is just the image of $\bf A$ under the Householder transformation corresponding to the unit vector $\frac{\bf C}{|{\bf C}|},$ and so $$\color{#bf0000}{\boxed{{\bf B} = {\bf A} - 2 \left(\frac{{\bf A} \cdot {\bf C}}{{\bf C} \cdot {\bf C}}\right){\bf C}}} .$$
If one doesn't know about Householder transformations, there's a quick way to derive this formula just using a little vector geometry: Given a parameterization ${\bf L}(t)$ of the line, we are looking for the points where ${\bf L}(t)$ has distance $R$ from the origin, and we can write this condition as $${\bf L}(t) \cdot {\bf L}(t) = R^2 .$$
Now, we have a point $\bf A$ on the line and a direction vector $\bf C$, so we can parameterize the line by $${\bf L}(t) := {\bf A} + t{\bf C}.$$ Substituting this formula in our condition gives $$R^2 = ({\bf A} + t{\bf C}) \cdot ({\bf A} + t{\bf C}) = {\bf A} \cdot {\bf A} + 2 t {\bf A} \cdot {\bf C} + t^2 {\bf C} \cdot {\bf C} .$$ On the other hand, since $\bf A$ is on the sphere, we have ${\bf A} \cdot {\bf A} = R^2$, and so the above equation simplifies to $$0 = t (2 {\bf A} \cdot {\bf C} + t {\bf C} \cdot {\bf C}) .$$ The r.h.s. is zero iff $t = 0$ or $(2 {\bf A} \cdot {\bf C} + t {\bf C} \cdot {\bf C}) = 0$. When $t = 0$, we have ${\bf L}(0) = {\bf A}$, which is our starting point, so we're interested in the other case. Rearranging and solving for $t$ gives that the other time at which the line intersects the sphere is $$t^* := -2 \frac{{\bf A} \cdot {\bf C}}{{\bf C} \cdot {\bf C}} .$$ Substituting gives that the intersection point is $${\bf B} = {\bf L}(t^*) ={\bf A} - 2 \left(\frac{{\bf A} \cdot {\bf C}}{{\bf C} \cdot {\bf C}}\right){\bf C}$$ as claimed.