Judging convex polygon by cross multiplication of two-dimensional vectors

Source: Internet
Author: User
The problem of judging convex polygon by vector fork multiplication
I'm doing a problem, the title is to give the coordinates of several points in a counter-clockwise order, to find out whether the polygon is concave or convex.

I saw a formula on the Internet:

Three points on the plane: P1 (x1,y1), p2 (x2,y2), P3 (X3,Y3)

S (p1,p2,p3) = (x1-x3) * (y2-y3)-(X2-X3) * (Y1-Y3)

If s>0 indicates that these 3 points are connected in a counterclockwise order, if S<0 then the connection 3 points are in a clockwise order
In this way, the sequential traversal of every three points, if there is less than 0 of the instructions there is a straight line to the right, the following figure:



So as long as there is a right turn, it means that the polygon is a concave polygon.

But I don't quite understand why the formula is deduced ...? It's called a vector fork.

We ask you to answer them greatly

------Solution--------------------
I think there is a relationship with sin angle, 0-180 degrees is positive, 180-360 is negative, the inner corner of a polygon is less than 180, then it is convex; The rest may be math problems. such as A²+b²-c²=2abcosc ... In the coordinate system to calculate ...
------Solution--------------------
As a space of three points: P1 (x1,y1,0), p2 (x2,y2,0), P3 (x3,y3,0)

L31 = P3-&GT;P1 = [(X1-X3), (Y1-y3), 0]
L32 = P3-&GT;P2 = [(X2-X3), (Y2-y3), 0]

L31xl32 = [0,0, (X1-X3) * (y2-y3)-(X2-X3) * (Y1-Y3)]
Equivalent to L31xl32 = S (p1,p2,p3) = (x1-x3) * (y2-y3)-(X2-X3) * (Y1-Y3)

The logical meaning of this vector product is that its results can be judged by whether the steering from L31-I-L32 is clockwise or counterclockwise.
Take your picture as an example:

Point 2 3 4 when the composition of L42, L43, two cross product can use the right hand rule L42 turn L43 found that the thumb is outward equivalent is positive.
Point 3 4 5 when the composition of L53, L54, two fork product right-hand rule L53 turn L54, you can find that the thumb is the equivalent of negative in the inward.

This function is equivalent to the last point to determine the first two points in the line composed of the left or right, and then to the end of the bend to which side.

Personal understanding, only for reference.

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.