On one side of a straight line? Is the point in a rectangle, triangle, or polygon?

Source: Internet
Author: User
Tags x2 y2

The judgment point is on one side of the straight line.

Method 1:

Http://zhidao.baidu.com/question/47341112.html

If we know P (0, 0), Q (3, 2) two points, we try to determine whether p and q are on the same side of the line 2x + 3y = 4.

Solution: Straight Line 2x + 3y = 4
That is, the line is 2x + 3y-4 = 0
Replace p and q with 2x + 3y-4 to get
2*0 + 3*0-4 =-4 <0
2*3 + 3*2-4 = 8
So on both sides!

Method 2:

Http://www.cnblogs.com/carekee/articles/1877575.html

How can we determine which side of the line is the point P of the (XP, YP) coordinate?

The straight line is determined by the first two points (x1, Y1) and (X2, Y2). The straight line direction is from (x1, Y1) to (X2, Y2.

Assume that the linear equation is AX + by + c = 0:

A = y2-y1; B = x1-x2; C = x2 * y1-x1 * Y2;

In this case, you can calculate d to determine which side of the line P is located:
D = A * XP + B * YP + c

If D <0, P is on the left side of the line; if D> 0, P is on the right side of the line; if D = 0, P is on the line.

Note: The line here has a direction!

Method 3: Use Vector computing to quickly determine which side of a straight line

Http://www.cnblogs.com/vilyLei/articles/1567852.html

For example, vector A × vector B = vector C
Suppose vector A turns to vector B at an angle less than 180 degrees.
Point the four fingers in the right hand to the direction of vector A, and the four fingers in the right hand bend to represent the direction of the above rotation, then the straight thumb points to their cross-Multiplied vector C
If the direction of vector C is the same, it is on the same side; otherwise, it is on both sides.

Note: The crossover calculation formula!

Http://hi.baidu.com/foreshore/blog/item/693bce3d9b8cf2c19f3d6218.html

If the vector is represented by coordinates (3D vector), the vector A = (x1, Y1, Z1), and the vector B = (X2, Y2, Z2), then:

Point multiplication is also called the Inner Product and number product of a vector.

Vector A · vector B = | A | B | cos <A, B>; vector A · vector B = x1x2 + y1y2 + z1z2

Cross multiplication is also called the outer product and vector product of a vector.

| Vector c | = | vector A × vector B | = | A | B | sin <A, B>

The direction of vector C is perpendicular to the plane of A and B, and must be determined by the "right hand rule ".
(The four fingers in the right hand first represent the direction of vector A, and then the fingers swing in the direction of the palm <180 to the direction of vector B, and the direction indicated by the thumb is the direction of vector C );

Vector a × vector B = | I j k |
| X1 Y1 Z1 |
| X2 Y2 Z2 |
= (Y1z2-y2z1, x2z1-x1z2, x1y2-x2y1)

(I, j, and K are the unit vectors of the three vertical coordinate axes in the space)

The outer product of a vector does not conform to the multiplication exchange rate.

Vector a × vector B =-vector B × vector

 

Determines whether a vertex is in a rectangle or polygon.

Http://blog.csdn.net/qiulei563/article/details/4869692

Http://mniwjb.blog.sohu.com/58905924.html

Http://dev.gameres.com/Program/Abstract/Geometry.htm

 

Method 1:

You only need to determine whether the horizontal and vertical coordinates of the point are between the left side of the rectangle and the upper and lower sides.

For example, the four vertices of a rectangle, P1, P2, P3, and P4, determine whether P is contained in the rectangle,

You only need to judge: | P2P | × | p2p1 | * | p3p | × | p3p4 | <= 0 and | p1p | × | p1p4 | * | P2P | × | p2p3 | <= 0

Method 2: Determine whether points are included in a polygon.

Take this vertex as the vertex and make a ray so that any of the four vertices of the rectangle is not on the ray.

If the ray has only one intersection point with the rectangle, it is in the rectangle; if there are zero or two focal points, it is outside the rectangle.

As for rays, you can select a point outside the rectangle and train it into a line segment with a known point.

As long as the coordinate of the vertex is not left ~ of the rectangle ~ Right, bottom ~ Within the top range.

 

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.