对角线多边形内或在其外?对角线、多边形

2023-09-11 02:35:19 作者:霸气丨籠爷丶

我已经连续三个点多边形的,说的P1,P2,P3。现在我想知道P1和P3之间的正交是否是内部的多边形或多边形之外。

I have three consecutive points of polygon, say p1,p2,p3. Now I wanted to know whether the orthogonal between p1 and p3 is inside the polygon or outside the polygon.

我通过采取三个矢量V1,V2和V3这样做。而在多边形的点p1点之前说P0。 V1 =(P0 - P1) V2 =(P2 - P1) V3 =(P3 - P1)

I am doing it by taking three vectors v1,v2 and v3. And the point before the point p1 in polygon say p0. v1 = (p0 - p1) v2 = (p2 - p1) v3 = (p3 - p1)

参照this的问题,我使用的这个问题公认的答案所示的方法。它仅作逆时针方向。如果我的点是顺时针什么。

With reference to this question, I am using the method shown in the accepted answer of that question. It is only for counterclockwise. What if my points are clockwise.

我也知道我的整个多边形是顺时针或逆时针。并据此我选择向量v1和v2。不过还是我得到了一些问题。我显示一种情况,我得到的问题。

I am also knowing my whole polygon is clockwise or counterclockwise. And accordingly I select the vectors v1 and v2. But still I am getting some problem. I am showing one case where I am getting problem.

这多边形是逆时针。并且它是从v1和v2的原点开始。

This polygon is counterclockwise. and It is starting from the origin of v1 and v2.

推荐答案

既然你点cnosecutive,您可以通过检查三角P1,P2,P3的方向解决这个问题。如果方向是一样的多边形中的一个,那么对角是在内部,否则在外面。

Since your points are cnosecutive, you can solve this problem by checking the orientation of the triangle p1 p2 p3. If the orientation is the same as the one of the polygon, then the diagonal is in the inside, else on the outside.

要确定的三角形的方向,最简单的方法是计算签名区,并检查标志。计算

To determine the orientation of the triangle, the simplest way is to compute the signed area and check the sign. Compute

p1.x * p2.y + p2.x * p3.y + p3.x * p1.y - p2.x * p1.y - p3.x * p2.y - p1.x * p3.y

如果这个值的符号为正,朝向是逆时针方向。如果符号为负,朝向是顺时针

If the sign of this value is positive, the orientation is counterclockwise. If the sign is negative, the orientation is clockwise.

要为precise,上述方法只给你上的多边形的边对角所在的信息。显然,多边形仍可相交对角线在稍后点

To be precise, the above method only gives you information on which side of the polygon the diagonal lies. Obviously, the polygon can still intersect the diagonal at later points.