Method for Determining whether a vertex is in a triangle

Source: Internet
Author: User

1. Call an API.

 
Bool ptinregion (hrgn, // handle to region int X, // X-coordinate of point int y // y-coordinate of point); hrgn createpolygonrgn (const point * lppt, // array of points int cpoints, // number of points in array int fnpolyfillmode // Polygon-filling mode );

II,

If the triangle is set to ABC, the judgment point is P area, indicating the area function.

Determine the relationship between area (PAB) + area (PAC) + area (PBC)-area (ABC) and 0.

If the value is greater than 0, it is outside the triangle.

0 is inside the triangle.

 

III,

Set three triangle points
A (A1, A2), B (b1, b2), C (C1, C2)
Three edge Equations
BC: Fa (x, y) = 0
AC: FB (x, y) = 0
AB: FC (x, y) = 0
Taking BC as an example, the point in the Triangle must be on the same side with the point a in BC.
So for vertex d (x, y)
In a triangle, you must first meet FA (x, y) * Fa (a1, a2)> 0
The same applies to other edges.
Therefore, you only need to compare
FA (x, y) * Fa (a1, a2)
FB (x, y) * FB (b1, b2)
FC (x, y) * fc (C1, C2)
Positive and Negative Numbers
1. All three numbers are positive: D is in the triangle.
2. There must be at least one negative number: D is outside the triangle.
3 There is only one 0, and the other two are positive numbers: on the edge of the triangle
4. There is only one zero, one positive number and one negative number: the extension line of the triangle edge is also counted outside the triangle, because 2 is satisfied.
5 has two zeros: On the vertex of the triangle
6. There cannot be 3 0, 3 negative, or 0 negative.

 

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.