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
    Aug 10 at 9:37
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$
2
  • 1
    $\begingroup$ Shouldn’t that be dot(N,N)? $\endgroup$ Aug 12 at 16:23
  • $\begingroup$ oops, yes thanks $\endgroup$
    – pmw1234
    Aug 12 at 22:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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