CS430 Computer Graphics Vectors Part III Intersections Chi-Cheng Lin, Winona State University Topics Intersection of Two Line Segments Application – Excircle Intersection of Line and Plane 2 Intersection of Two Line Segments Problem: Given two line segments AB and CD, determine whether they intersect, and if they do, find the intersection point Cases D B B A D C A D A D C B A C C B A C D B A C B D 3 Parametric Line AB(t) = A + bt, where b = B -A - < t < : parent line of AB 0.0 t 1.0: line segment AB 0.0 t < : ray B A t <0 t >1 t =1 t =0 4 Intersection of Two Line Segments AB(t) = A + bt, where b = B -A CD(u) = C + du, where d = D -C Parent lines of AB and CD intersect if A + bt = C + du Let c = C - A b t = c + du d•bt = d•c + d•du d•bt = d•c 5 Intersection of Two Line Segments Case I: d•b 0 AB and CD are not parallel (why?) t = (d•c)/(d•b) Similarly, (how?) u = (b•c)/(d•b) Q: When do two AB and CD intersect? A: When 0.0 t 1.0 and 0.0 u 1.0 6 Intersection of Two Line Segments Case II: d•b = 0 AB and CD are parallel If (bc) = 0, the line segments are colinear (why?) have to test for overlap If (bc) 0, the line segments are not colinear they do not intersect Examples 7 Application – Circle through 3 Points Given 3 non-collinear points A, B, and C, find the circle passing through the 3 points excircle of triangle defined by the points The center S is the intersection of the perpendicular bisectors of AB, BC, and CA A A ? B C S B C 8 Circle through 3 Points Let a = B - A, b = C - B, c = A – C Midpoint of A = A + a/2 (why?) Direction perpendicular to AB = a Parametric form of perpendicular bisector of AB = A + a/2 + at (why?) Parametric form of perpendicular bisector of CA = C + c/2 + cu 9 Circle through 3 Points The intersection of AB and CA is S A + a/2 + at = C + c/2 + cu As a + b + c = 0 (why?) at = b/2 + cu (how?) t = 0.5(bc)/(ac) (how?) center S A 1 (a b c a ) 2 a c a bc 2 ( ) 1 radius = |S - A| = 2 a c 10 Intersection of Line and Plane Line in parametric form R(t) = A + ct where A is a known point on the line c is the direction vector of the line R is a point on the line If t is allowed to vary from 0 to infinity, R(t) is a ray 11 Intersection of Line and Plane Plane in point normal form n(P -B) = 0 where n is a normal vector to the plane B is a known point on the plane P is any other point on the plane If P is not on the plane, n(P -B) 0 12 Intersection of Line and Plane If a ray R(t) intersect the plane, then n(R(t) -B) = 0 (we want to find t) n(A + ct -B) = 0 n(A -B) + nct = 0 t (nc) = n(B -A) P P 13 Intersection of Line and Plane Case I: nc 0 t = n(B -A)/(nc) “Hit point” P = A + ct Case II: nc = 0 ray and plane are parallel If n(B -A) = 0, the ray lies on the plane Otherwise, there is no intersection 14 Direction Ray Hits the Plane If nc > 0 < 90o Ray is aimed along with the normal If nc = 0 = 90o Ray is parallel to the normal If nc < 0 > 90o Ray is aimed counter to the normal n n c A along with A c counter to 15