Where the line and the point function for the endpoint
526 Chapter 11 Intersection Testing
To do this, we return to calculus. To find a minimum value (in this case there is only one) for a function, we find a place where the derivative is 0. Taking the derivative of equation 11.6 in terms of tc, we get the result
closest point between a line and a point, where the line is L2 and the point is P0.
function is For the s = 1 endpoint, we follow a similar process. Our minimization
tc =v · w0 + u · v v · v
Again, this is equivalent to computing the closest point between a line and a point, where the line is L2 and the point is P0 + v. The solutions for sc when clamping to t = 0 or t = 1 are similar. One nice thing about these functions is that they use the a through e values that we’ve already calculated for the basic lineline distance calculation.
Once again, there is a trick we can do to avoid multiple floatingpoint
divisions. Instead of computing, say, sc directly and testing against 0 and 1, we can compute the numerator sN and denominator sD. The initial sD is always greater than zero, so we know that if sN is less than zero, sc is less than zero and we clamp to s = 0 accordingly. Similarly, if sN is greater than sD, we know that sc > 1, and we clamp to s = 1. The same can be done for the t values. Using this, we can recalculate the numerator and denominator when necessary, and
11.2.8 Line Segment–Line Segment Distance



