"Algorithm problem combat strategy"-chaper15-compute Geometry-segment intersection

Source: Internet
Author: User

This article focuses on the intersection of line segments.

Given two line segments, how can I tell if the two segments intersect?

If the two segments intersect, how do you find the intersection?

Line intersection problem is usually because of its complicated situation of the kind of people to avoid and far, here hope through the author's simplified discussion hope to help readers to comb the idea.

First, we try to draw a few geometric images to find out the intersection of a number of different cases, it is important to note that there may be readers will be curious, these intuitive to see the intersection of no difference, why do we think they are different? The answer is, here we need to use algebraic representations of geometric features to make judgments, so different geometric features, although all represent segments intersect, but the corresponding algebraic expressions are not necessarily the same.

The simple function code is as follows:

//General conditions of intersection of segmentsBOOLsegmentintersects (Point A1, Point A2, point B1, point B2) {DoubleC1 = Cross (A2-A1, b1-A1); DoubleC2 = Cross (A2-A1, b2-A1); DoubleC3 = Cross (B2-B1, a1-B1); DoubleC4 = Cross (B2-B1, a2-B1); if(DCMP (C1) *dcmp (c2) = =0&& dcmp (C3) *dcmp (C4) = =0)      {            if(Onsegment (Point A1, Point B1, point B2) | |Onsegment (Point A2, point B1, point B2))return true; Else                  return false; }           return if(DCMP (C1) *dcmp (C2) <=0&& dcmp (C3) *dcmp (C4) <=0)}

"Algorithm problem combat strategy"-chaper15-compute Geometry-segment intersection

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.