<p>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 <span class="math-container">$v$</span> and <span class="math-container">$d$</span> are unit vectors. Let's call the projected point <span class="math-container">$x$</span>.</p>

<p>First, because the projected point is in the direction <span class="math-container">$d$</span>, we can write:
<span class="math-container">$$\vec{vx} = \lVert\vec{vx}\rVert d $$</span></p>

<p>Second, because <span class="math-container">$p$</span> and <span class="math-container">$x$</span> are on the plane and <span class="math-container">$n$</span> is the plane normal, we can write:
<span class="math-container">$$\vec{vx}\cdot n = \vec{vp}\cdot n$$</span></p>

<p>We can now work on the equation until we get a definition for <span class="math-container">$\vec{vx}$</span>:
<span class="math-container">$$\begin{align}
\vec{vx}\cdot n &amp; = \vec{vp}\cdot n \\
\lVert\vec{vx}\rVert d\cdot n &amp; = \vec{vp}\cdot n \\
\lVert\vec{vx}\rVert &amp; = \frac{\vec{vp}\cdot n}{d\cdot n} \\
\vec{vx} &amp; = \frac{\vec{vp}\cdot n}{d\cdot n}d \\
\end{align}$$</span></p>

<p>Or written differently:
<span class="math-container">$$x = v + \frac{(p-v)\cdot n}{d\cdot n}d$$</span></p>

<p><em>The result is undefined when the scalar product <span class="math-container">$d \cdot v$</span> is <span class="math-container">$0$</span>, which happens when <span class="math-container">$d$</span> and <span class="math-container">$n$</span> are orthogonal, when <span class="math-container">$d=0$</span>, or when <span class="math-container">$n=0$</span>. The first case means <span class="math-container">$d$</span> 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.</em></p>

CC BY-SA 4.0
2018-11-19T07:15:46.407Z
2018-11-19T16:41:26.647Z
2018-11-19T16:41:26.647Z
Julien Guertault
<p>What I have:</p>

<ul>
<li>a plane given by its normal<span class="math-container">$\ n $</span> and a point on the plane<span class="math-container">$\ p $</span>.</li>
<li>a 3D-point<span class="math-container">$\ v $</span>.</li>
<li>a direction<span class="math-container">$\ d$</span>.</li>
</ul>

<p>What I need:</p>

<ul>
<li>the projection of<span class="math-container">$\ v$</span> along<span class="math-container">$\ d$</span> onto the plane.</li>
</ul>

<p>How can I calculate this? Thank you!</p>

<p>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. :-)</p>

<opengl><projections><shading><linear-algebra>
Project vertex onto plane
Dmitrii C.
# Project vertex onto plane

(Asked by: username_0 on 2018-11-18)

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. :-)

**Tags:** opengl, projections, shading, linear-algebra


---

## 1 answers

### Answer by username_1 on 2018-11-19. Score: 2 | Accepted answer

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.*


---

