1
$\begingroup$

What I have:

  • a plane given by its normal$\ n $ and a point on the plane$\ p $.
  • a 3D-point$\ v $.
  • a direction$\ d$.

What I need:

  • the projection of$\ v$ along$\ d$ onto the plane.

How can I calculate this? Thank you!

P.S.: I need to implement that in GLSL, in case this is of any information. I would be fine with the formula so that I can work out the implementation myself, anyways. :-)

$\endgroup$

1 Answer 1

2
$\begingroup$

To answer your question we just need to write it as linear algebra equations and solve them. Although your question doesn't state it, I assume that $v$ and $d$ are unit vectors. Let's call the projected point $x$.

First, because the projected point is in the direction $d$, we can write: $$\vec{vx} = \lVert\vec{vx}\rVert d $$

Second, because $p$ and $x$ are on the plane and $n$ is the plane normal, we can write: $$\vec{vx}\cdot n = \vec{vp}\cdot n$$

We can now work on the equation until we get a definition for $\vec{vx}$: $$\begin{align} \vec{vx}\cdot n & = \vec{vp}\cdot n \\ \lVert\vec{vx}\rVert d\cdot n & = \vec{vp}\cdot n \\ \lVert\vec{vx}\rVert & = \frac{\vec{vp}\cdot n}{d\cdot n} \\ \vec{vx} & = \frac{\vec{vp}\cdot n}{d\cdot n}d \\ \end{align}$$

Or written differently: $$x = v + \frac{(p-v)\cdot n}{d\cdot n}d$$

The result is undefined when the scalar product $d \cdot v$ is $0$, which happens when $d$ and $n$ are orthogonal, when $d=0$, or when $n=0$. The first case means $d$ is parallel to the plane and the projection doesn't have a point solution, and the two other cases mean that either the plane or the projection are not defined.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.