# Help understanding tangent from dot product and max distance from component wise vector multiplication

I am looking through this code 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.

• I'm not sure if it helps, but the same functions seem to be implemented in C++ in this function. They seem to make more sense there. Aug 10, 2021 at 9:37

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