问题标签 [point-in-polygon]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
1909 浏览

java - 从 Line2D 值添加多边形点

我有一小段代码从名为 lineList 的数组(在不同的类中)读取 Line2D 值,并将它们存储在名为 list 的新数组中。从这里开始,我一直在尝试将所有线值转换为多边形点(线端的每个 x、y 坐标的一个点)。

到目前为止,我已经让它工作了,但它不适用于添加的数组中第一行的第一个点(这就是我怀疑的),我无法找到解决方案,因为我已经尝试将它包含在第一个 if 语句。

我将非常感谢任何人能够为此提供的任何帮助。

下面是我用于从 Line2D 值添加点的代码:

下面是第一个点(最低点)不包含在多边形点中的示例。 在此处输入图像描述

0 投票
1 回答
130 浏览

mysql - SQLintersects 查询无法正常工作

我正在尝试从我的表中选择位于特定多边形中的点。
这里我的表 test1 有几何类型的 data4 列,它包含:

当我尝试以下查询时,它返回空行。请帮我解决错误。

我也试过:

这也没有奏效。

0 投票
2 回答
419 浏览

java - 简单的java游戏:填充由移动光标绘制的图形

所以我正在做一个介绍 Java 课程的项目,似乎我选择了一些超出我能力范围的东西。:P
任何帮助将不胜感激。这就是我遇到的问题:

您有一个由玩家控制的光标(向前或转动 90°),它会留下一条彩色线。如果您设法越过自己的线并关闭任何形状的多边形(尽管只有直角),它的表面会将颜色变为您的线的颜色。

我可以检测到这种情况何时出现,但我有点迷失了如何实际填充刚刚关闭的正确多边形。我似乎无法想象一种算法可以涵盖任何可能的情况。

我查看了扫描线填充算法,但我认为当地图中已经填充了一些多边形时,它就会开始出现问题。如果我有办法在多边形内找到一个点,Floodfill算法将是完美的,但是,由于有许多不同的可能性,我想不出一个通用的规则。

我正在使用一个 2x2 整数数组,其中每种颜色都由一个数字表示。

有谁知道如何解决这个问题?

0 投票
2 回答
13776 浏览

mysql - 使用 MySQL 在表中搜索 Point in Polygon

我在 MySQL 5.5 中创建了一个包含一些边界的表 (municipal_border)。

字段 urbanID 不是唯一的。

我正在使用下面的代码来测试一个点是否属于多边形。

第一个语句 set @r = ... 只返回一行,我专门选择它进行测试。它工作得很好。

我想要做的是搜索整个表(换句话说,擦除 SQL 问题中的 WHERE 部分)并找到该点在哪个多边形中。

0 投票
2 回答
964 浏览

google-maps - Point in KML Polygon - C / C++ code

I am looking for C or C++ code to identify whether the point (a co-ordinate) lies inside a KML polygon or not.

I have searched but all I got is javascript (google maps apis) which can achieve the same. I cannot even port it directly because I have a slight modified requirement:

  1. Identify whether given co-ordinate lies within polygon of KML (the code should exclude holes in the polygon too!).
  2. Informing the caller the distance to the nearest polygon edge if the point is outside the range.

As far as I have researched, the 2nd point has not been achieved anywhere yet. I would want to know how to achieve this in C or C++? Or, have I missed searching any existing sources?

Would like to have inputs.

0 投票
3 回答
2264 浏览

python - 凸多边形中的点

我正在尝试创建一个函数,True如果给定的 (x,y) 点位于凸多边形内,则该函数将返回。我试图让它没有 numpy 或任何类似的导入,只是纯 python 代码。

我已经找到了一个示例解决方案,乍一看似乎还可以,但它不能正常工作,我不知道为什么。代码如下:

如果我对 (9,9) 进行测试,对于以下多边形,它会给我True

但是当我改变多边形点的顺序时,对于同一个点,它给了我False

有人知道原因吗?谢谢!

0 投票
2 回答
2063 浏览

python - matplotlib pnpoly 示例导致错误

我按照此处的示例运行了以下代码:

http://matplotlib.org/faq/howto_faq.html#test-whether-a-point-is-inside-a-polygon

非常感谢您的帮助。谢谢你。

0 投票
2 回答
1195 浏览

algorithm - 查找包围点的多边形的算法 - 仅定义线

我有一张带有许多直线的 2D 绘图。所有这些线在数学上都是已知的。他们独立于其他人。

您可以考虑我知道每条线的起点和终点,我可以使它们相交以找到所有交点。(详细地说,它们在 Autocad 中,但我只能通过代码工作。所以,我想要一个算法而不是 Autocad 解决方案,尽管也欢迎 Autocad 解决方案)。

问题是:给定一个点(任何地方),我想找到包含它的较小多边形。该多边形将由最近的线形成。


细节:

我没有声明的多边形。只是线条。任意数量的行,任意大小,任意位置。和一个给定的点。

这些线可能形成一个多边形,多或无。因此,多边形的外观没有规则。任意数量的边,没有规律性。(形成多边形的点是通过与线相交来找到的。线是有限的,如果它们不相交,它们就不会形成多边形。)

我的答案是包含给定点的最小多边形。

0 投票
1 回答
106 浏览

javascript - 检查某个多边形内部的有效方法

在我的 JavaScript 应用程序中,我有 30 多个多边形。它们的定义如下:

现在给定一个像 [10,10] 缩放 4 的点。

检查该点位于哪个多边形内的快速方法是什么?

我的第一个想法是迭代多边形,并检查该点是否在多边形内。

然后这个问题变成了一个多边形问题,在stackoverflow上有很多答案。

我只是想知道是否有任何替代方法?

0 投票
2 回答
6479 浏览

javascript - How to check if point is in polygon in Javascript

I came across this piece of C code (I think) that's supposed to be a neat way to check if a point is within a concave or convex polygon, and I would like to convert it to a JS equivalent function to use in my JS program:

#xA;

nvert: Number of vertices in the polygon. Whether to repeat the first vertex at the end.
vertx, verty: Arrays containing the x- and y-coordinates of the polygon's vertices.
testx, testy: X- and y-coordinate of the test point.

Code above taken from this Stack Overflow question.

How would this translate into JS? I've already found out how I can start the for-loop in JS

#xA;

And I guess that the "float *"s in the first row can just be omitted in JS. But I'm not quite sure what the "int i, j, c = 0;" does or what "!c" means when "c = 0". What's the opposite of 0?

Thanks!