Determine whether the vertex is in the triangle by cross Multiplication

Source: Internet
Author: User

Cross Multiplication

Walk along the side of the triangle clockwise to determine whether the vertex is on the right side of each edge (which can be determined by cross multiplication). If the vertex is on the right side of each edge, it is within the triangle, otherwise it is outside the triangle. ThisAlgorithmOnly triplicate multiplication is used. Division operations and trigonometric functions and root numbers are not used. Therefore, the efficiency and accuracy are high (no floating point error ).

Set the triangle to three points A (x1, Y1) B (X2, Y2) C (X3, Y3), known points M (x, y ),

1. first obtain the three vectors Ma, MB, MC.

2. Calculate Ma x mb, MB x MC, MC x Ma (x table cross multiplication)

3. If the result of the vector cross-multiplication in these three groups is of the same number (both positive and negative), that is, the direction is the same, it indicates that the vertex M is on the same side of each triangle, that is, inside. Otherwise, it must be external!

Example:
A (0, 3) B (0, 0) C (3, 0)

M (1, 1)
MA (1,-2)
MB (1, 1)
MC (-2, 1)

Ma x mb = 3
MB x MC = 3
MC x MA = 3

N (3, 3)
Na (3, 0)
NB (3, 3)
NC (0, 3)

Na x Nb = 9
NB x NC = 9
NC x NA =-9

Based on the above rules, we can determine that M points are outside N points.

 

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.