|
|
> Okay, let's look at this in detail:
>
> if ((Triangle->P2[Y] - s) * (Triangle->P2[Z] - Triangle->P1[Z]) <
> (Triangle->P2[Z] - t) * (Triangle->P2[Y] - Triangle->P1[Y]))
> {
> return(false);
> }
>
> It becomes clearer if we flip the signs:
>
> if ((s - Triangle->P2[Y]) * (Triangle->P1[Z] - Triangle->P2[Z]) <
> (t - Triangle->P2[Z]) * (Triangle->P1[Y] - Triangle->P2[Y]))
> {
> return(false);
> }
>
> Note that all the differences in there actually constitute a translation by -P2,
> so we get a statement of the form:
>
> if (A[Y] * B[Z] < A[Z] * B[Y]) ...
>
> which is a more robust way of comparing A[Y]/A[Z] with B[Y]/B[Z], which gets
> unnecessarily nasty in certain cases (and, as it seems, would be more
> problematic regarding the signs, and choice of > vs. <).
>
> So in essence the idea is to compare the "direction coefficients" (don't know if
> that's the proper English word) of the line equations of (A) the line through P2
> and the intersection point, and (B) the line through P2 and P1.
>
> You can also think of it in terms of a vector dot product:
>
> if (A[Y] * B[Z] < A[Z] * B[Y]) ...
>
> is equal to:
>
> if (A[Y] * B[Z] + A[Z] * (-B[Y]) < 0) ...
>
> which happens to be the dot product of A and a vector perpendicular to B
> (compared with zero).
>
> Interpreted this way, the test boils down to checking whether the angle between
> A, and that particular perpendicular to B, is greater or smaller than 90
> degrees.
Thanks a lot. I get it now.
Post a reply to this message
|
|