C ++ determines whether a vertex is in a plane

Source: Internet
Author: User

Direct function:

Bool ctriobject: ptinpolygon (point P, point * ptpolygon, int ncount) {// Number of intersections int ncross = 0; For (INT I = 0; I <ncount; I ++) {Point P1 = ptpolygon [I]; point P2 = ptpolygon [(I + 1) % ncount]; // link the last vertex to the first vertex if (p1.y = p2.y) continue; If (P. Y <min (p1.y, p2.y) continue; If (P. y> = max (p1.y, p2.y) continue; // returns the X coordinate Double X = (double) (p. y-p1.y) * (double) (p2.x-p1.x)/(double) (p2.y-p1.y) + p1.x; // only count the intersection of P1P2 and P to the right if (x> P. x) {ncross ++; }}// the intersection is an even number. Return (ncross % 2 = 1) outside the polygon );}

 

 

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.