1
$\begingroup$

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.

$\endgroup$
1
  • $\begingroup$ 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. $\endgroup$
    – gilgamec
    Commented Aug 10, 2021 at 9:37

1 Answer 1

2
$\begingroup$

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

$\endgroup$
1
  • 1
    $\begingroup$ Shouldn’t that be dot(N,N)? $\endgroup$ Commented Aug 12, 2021 at 16:23

Your Answer

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

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