Finding the intersection of lines and segments
Finding intersections
Determining the score point method, using the cross product to calculate the area, using the area ratio to replace the segment length ratio
Point Inter_point (Point a,point b,point c,point D)///returns the intersection of Line AB and segment CD{ if(!intersect (A,B,C,D))return{-inf*1.0,0};///To determine if the line AB intersects the segment CD, the non-intersect must be special DoubleArea1=fabs ((b-a) * (C-A)); DoubleArea2=fabs ((b-a) * (dA)); Doublex= (area1*d.x+area2*c.x)/(area1+area2); Doubley= (AREA1*D.Y+AREA2*C.Y)/(area1+area2); return{x, y};}
View Code
Judgment intersection, cross product judgment left and right (across the experiment)
bool intersect (Point a,point b,point c,point D) /// determine if line AB intersects the segment CD { if returntrue; return false ;}
View Code
If the segment intersection is judged, it is necessary to use the quick Exclusion experiment and the cross-experiment
To find the intersection of a segment must first determine the intersection
About lines and segments