About lines and segments

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.