<p>There is very little geometrical meaning to the multiplication of two vectors and there are no well defined identities describing the result. But that doesn't make it illegal, and is an important part of many well defined functions such as the dot product.</p>
<p>Multiplication of vectors also have several important identities that allow terms to be moved around in a larger function. And it looks like that is what is going on here. The function this code is in returns the sum of the products after clipping it against the min/max of the bounding box, and contains magnitude and direction. (think dot product)</p>
<p>The code <span class="math-container">$tng = d - dot(d, N) * N$</span> is called vector rejection. That is, find the component of a vector <span class="math-container">$d$</span> that is perpendicular to <span class="math-container">$N$</span>. Vector rejection usually includes a division by <span class="math-container">$dot(N,N)$</span> but that can be skipped in some cases. (like if the vector <span class="math-container">$N$</span> is normalized).</p>

CC BY-SA 4.0
2021-08-12T16:23:13.477Z
Shouldn’t that be _dot(N,N)_?
Noah Witherspoon
CC BY-SA 4.0
2021-08-12T12:43:42.643Z
2021-08-12T22:41:30.773Z
2021-08-12T22:41:30.773Z
pmw1234
<p>I am looking through <a href="https://github.com/DQLin/RealTimeStochasticLightcuts/blob/c18e888330323917dfb747a8ce53fd8220d45581/RealTimeStochasticLightcuts/Shaders/LightTreeUtilities.hlsli" rel="nofollow noreferrer">this code</a> and seeing two things which confuse me (well, the whole functions does) in the top functions.</p>
<p>First, <code>dir * p</code> where <code>dir</code> and <code>p</code> are vec3s. What does component wise multiplication of two vec3s give you in geometric terms? The function is clearly meant to give you the maximum distance along a vector to an AABB, but how we got there from a load of point-vector multiplications? I do not know.</p>
<p>Secondly, <code>tng = d - dot(d, N) * N</code>. Here, <code>d</code> is the shortest vector between a point and an AABB, and <code>N</code> is the point's normal. I can see <code>tng</code> is meant to say &quot;tangent&quot;, but I'm not seeing how we got from a normal and an effectively random vector to a tangent to something?</p>
<p>Also, I have read the papers this code is derived from, and they do not explain it. If anything they would suggest that just <code>clamp(p, boundMin, boundMax) - p</code> should be returned.</p>

CC BY-SA 4.0
2021-08-10T09:37:55.913Z
I'm not sure if it helps, but the same functions seem to be implemented in C++ in [this function](https://github.com/DQLin/RealTimeStochasticLightcuts/blob/c18e888330323917dfb747a8ce53fd8220d45581/RealTimeStochasticLightcuts/Source/CPULightCuts.h). They seem to make more sense there.
gilgamec
<mathematics><computational-geometry><geometry><shading><vectors>
Help understanding tangent from dot product and max distance from component wise vector multiplication
Jeff Streepe
# Help understanding tangent from dot product and max distance from component wise vector multiplication

(Asked by: username_0 on 2021-08-09)

I am looking through [this code](https://github.com/DQLin/RealTimeStochasticLightcuts/blob/c18e888330323917dfb747a8ce53fd8220d45581/RealTimeStochasticLightcuts/Shaders/LightTreeUtilities.hlsli) and seeing two things which confuse me (well, the whole functions does) in the top functions.

First, `dir * p` where `dir` and `p` are vec3s. What does component wise multiplication of two vec3s give you in geometric terms? The function is clearly meant to give you the maximum distance along a vector to an AABB, but how we got there from a load of point-vector multiplications? I do not know.

Secondly, `tng = d - dot(d, N) * N`. Here, `d` is the shortest vector between a point and an AABB, and `N` is the point's normal. I can see `tng` is meant to say "tangent", but I'm not seeing how we got from a normal and an effectively random vector to a tangent to something?

Also, I have read the papers this code is derived from, and they do not explain it. If anything they would suggest that just `clamp(p, boundMin, boundMax) - p` should be returned.

**Tags:** mathematics, computational-geometry, geometry, shading, vectors

> **Comments:**
> **username_1**: I'm not sure if it helps, but the same functions seem to be implemented in C++ in [this function](https://github.com/DQLin/RealTimeStochasticLightcuts/blob/c18e888330323917dfb747a8ce53fd8220d45581/RealTimeStochasticLightcuts/Source/CPULightCuts.h). They seem to make more sense there.  

---

## 1 answers

### Answer by username_2 on 2021-08-12. Score: 2

There is very little geometrical meaning to the multiplication of two vectors and there are no well defined identities describing the result. But that doesn't make it illegal, and is an important part of many well defined functions such as the dot product.

Multiplication of vectors also have several important identities that allow terms to be moved around in a larger function. And it looks like that is what is going on here. The function this code is in returns the sum of the products after clipping it against the min/max of the bounding box, and contains magnitude and direction. (think dot product)

The code $tng = d - dot(d, N) \* N$ is called vector rejection. That is, find the component of a vector $d$ that is perpendicular to $N$. Vector rejection usually includes a division by $dot(N,N)$ but that can be skipped in some cases. (like if the vector $N$ is normalized).

> **Comments:**
> **username_3**: Shouldn’t that be _dot(N,N)_?  

---

