在缓冲的MondoDB Linestring中使用$内部 [英] Use $within with a buffered MondoDB Linestring
问题描述
我需要使用MongoDB评估 Point
与 LineString
的接近程度。
由于 $ near
操作符只能将 Point
与另一个 Point
,我需要从 LineString
中生成一个多边形,所以我可以使用 $ within
运算符。 LineString和多边形边缘之间的距离应该代表我想要搜索的半径,例如下面用红色表示的那样:
为了达到这个目的,有什么可能是一种有用的算法? / p>
我觉得更容易的是编写自己的函数
要找到(垂直)点和线之间的距离,然后用多边形方法创建多线的厚度。
其中:
-
P0,P1
是行终点 -
P
-
d
就是它们之间的距离 -
创建垂直线
$ b-
q(t)= P + DQ * u
其中u =( - inf,+ inf)
-
DQ
是垂直向量(P1-P0)
在2D中,您可以像这样轻松获得
(x,y) - > (Y,-X)
。在较高维度中,使用具有一些非共面向量的叉积。 -
计算线与线交点
有很多关于此的东西,所以谷歌或自己解决方程式这里您可以提取我的实施。
-
-
现在成功交集后 code> d 作为
P
和交点之间的距离。不要忘记参数t
必须在范围内。如果不是(或者如果没有交集),那么返回min(| P-P0 |,| P-P1 |)
P0,P1
are line endpointsP
is pointd
is distance between themcreate perpendicular line
q(t)=P+DQ*u
whereu=(-inf,+inf)
DQ
is perpendicular vector to (P1-P0)
In 2D you can obtain it easily like this
(x,y) -> (y,-x)
. In higher dimensions use cross product with some non coplanar vectors.compute line vs. line intersection
there are tons of stuff about this so google or solve the equation yourself here you can extract mine implementation.
now after successful intersection
just compute
d
as distance betweenP
and intersection point. Do not forget that parametert
must be in range. If not (or if no intersection) thenreturn min(|P-P0|,|P-P1|)
<线被定义为:其中
t = <0.0,1.0> 其中p
所以函数应该这样做: p>
[提示]
$ b
t
和 u
参数可以直接从相交测试中获得,因此如果垂直向量为(P1-P0)
被标准化为 size = 1
,那么相交点的 abs(u)
参数就是距离
[注释]
我不熟悉 mongodb 你没有办法在里面使用自己的测试,那么这个答案是粗糙的过时。
I need to evaluate the proximity of a Point
to a LineString
using MongoDB.
Because the $near
operator can only compare a Point
to another Point
, I need to generate a polygon out of the LineString
, so I can use the $within
operator. The distance between the LineString and the edges of the polygon should represent the radius I want to search in, such as represented in red below:
What might be a useful algorithm in order to accomplish this?
I think much easier would be to write your own function
To find (perpendicular) distance between point and line and then creating thickness of poly-line by polygon means.
Where:
Line is defined as: p(t)=P0+(P1-P0)*t
where t=<0.0,1.0>
So the function should do this:
[hints]
t
and u
parameters can be obtained directly from intersection test so if the perpendicular vector to (P1-P0)
is normalized to size = 1
then the abs(u)
parameter of intersection point is the distance
[notes]
I am not familiar with mongodb so if you have no means to use own tests inside then this answer is of coarse obsolete.
这篇关于在缓冲的MondoDB Linestring中使用$内部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!