Upcoming SlideShare
×

# Closest point on line segment to point

16,501 views
16,031 views

Published on

1 Like
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

Views
Total views
16,501
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
16
0
Likes
1
Embeds 0
No embeds

No notes for slide

### Closest point on line segment to point

1. 1. Closest Point on line segment to point<br />
2. 2. Let AB be a line segment specified by the endpoints A and B. Given an arbitrary<br />point C, the problem is to determine the point D on AB closest to C. As shown in<br />Figure 5.2, projecting C onto the extended line through AB provides the solution. If<br />the projection point P lies within the segment, P itself is the correct answer. <br />
3. 3. Any point on the line through AB can be expressed parametrically as P(t) = A + t (B − A). Using the projective properties of the dot product, the t corresponding to the projection of C onto the line is given by t = (C − A) · n/ _B − A_, where n = (B − A)/ _B − A_ is a unit vector in the direction of AB.<br />
4. 4. Because the closest point on the line segment is required, t must be clamped to the interval 0 ≤ t ≤ 1, after which D can be obtained by substituting t into the parametric equation. <br />
5. 5. Closest points on two lines<br />
6. 6. We know that lines in 2D always intersect unless they are parallel. 3D is otherwise. They almost never intersect. It may seem that they do but due to rounding errors they just get really close but never intersect.<br />
7. 7. The closest points of two lines can be determined as follows:<br />Let the lines L1 and L2 be specified parametrically by the points P1 and Q1 and P2 and Q2:<br />L1(s) = P1 + sd1, d1 = Q1 − P1<br />L2(t) = P2 + td2, d2 = Q2 − P2<br />
8. 8. For some pair of values for s and t, L1(s) and L2(t) correspond to the closest points on the lines, and v(s, t) = L1(s)−L2(t) describes a vector between them.<br />
9. 9. The points are at their closest when v is of minimum length. The key realization is that this happens when v is perpendicular to both L1 and L2. To see this, consider that the shortest distance between a point P and a line L is the length of a straight line between P and the point Q corresponding to the orthogonal projection of P onto L.<br />Consequently, the line PQ is orthogonal to L. Because this reasoning holds for both L1(s) with respect to L2 and L2(t) with respect to L1, v must be perpendicular to both lines. For nonparallel lines, v is unique.<br />
10. 10. The problem is now finding values for s and t satisfying these two perpendicularity<br />constraints:<br /> <br />d1 · v(s, t) = 0<br />d2 · v(s, t) = 0.<br /> <br />Substituting the parametric equation for v(s, t) gives:<br /> <br />d1 · (L1(s) − L2(t)) = d1 · ((P1 − P2) + sd1 − td2) = 0<br />d2 · (L1(s) − L2(t)) = d2 · ((P1 − P2) + sd1 − td2) = 0.<br /> <br />This can be expressed as the 2 × 2 system of linear equations<br /> <br />(d1 · d1)s − (d1 · d2)t = −(d1 · r)<br />(d2 · d1)s − (d2 · d2)t = −(d2 · r),<br /> <br />where r = P1 − P2.<br />
11. 11. Written symbolically, in matrix notation, this corresponds to:<br />
12. 12. SOURCES:<br />Real Time Collision Detection by Morgan Kaufmann (book)<br />http://pastie.org/1066490<br />