相关疑难解决方法(0)

对于不规则多边形中的点,选择最接近该点的边的最有效方法是什么?

给定不规则多边形和该多边形内的点,如何确定多边形中哪条边最接近该点?

例

我可能必须对多边形内的一大组点(例如50-200点)运行此计算.

geometry computational-geometry

5
推荐指数
1
解决办法
4103
查看次数

指向最接近x,y的直线

可能重复:
如何确定点是否在某一线附近?

//Returns the point on the line traced from start to end which
//comes nearest to 500,000, 500,000. The points are scaled between
//1,000,000 and 0 from their original fp types.
Point closestToCentre(Point start, Point end);
Run Code Online (Sandbox Code Playgroud)

有人知道比单步穿过像素更快的方法吗?

能不能比我更警觉地证明他们的数学和几何能力了吗?

_______编辑___________

谢谢Kris,这让我感到困惑:

[X; -a/BX-C/B] = [0; -c/B] - 1/B [-b; 斧头.

现在我看到它只是将矢量(主要是y分量)分成两个,它们组合起来产生相同的结果.得到旧的部分分数脑细胞兴奋一分钟然后:)

_______编辑_________

杰森摩尔,感谢你的灵感,这就是我正在做的,从图形上看,

64x64平方,每条边缘到边缘有两条采样线,并且中心偏离一定距离

我希望这更清楚.

____编辑________

所以我可以合理地期望在我的采样线上采取直角线并从中心运行它但是如何判断它们何时触摸?

在此输入图像描述

我认为克里斯的方程式页面是要走的路.如果你们都告诉我这是一个两步的过程.现在只是两个联立方程,所以我可能不需要Kris的推导.

____编辑_________

无论好坏,我不知道,但作为搜索引擎的stackoverflow之美已向我揭示了几条调查路线.首先,我喜欢这里的第一个解决方案: 点和线段之间的最短距离.

但为了向我自己证明这一点,我需要matti的解决方案在底部(但是一个)的链接:

http://www.topcoder.com/tc?d1=tutorials&d2=geometry1&module=Static

推导是如此简单和优雅,即使我可以遵循它!

鉴于http://mathworld.wolfram.com/Point-LineDistance2-Dimensional.html

algorithm geometry

5
推荐指数
1
解决办法
2万
查看次数

计算到平滑线的距离

我试图找到一个点的距离(在4维中,这里只显示2个)(图中的任何彩色十字)到假定的帕累托边界(黑线).该线代表优化过程中最佳的Pareto前沿表示.

Pareto = [[0.3875575798354123, -2.4122340425531914], [0.37707675586149786, -2.398936170212766], [0.38176077842761763, -2.4069148936170213], [0.4080534133844003, -2.4914285714285715], [0.35963459448268725, -2.3631532329495126], [0.34395217638838566, -2.3579931972789114], [0.32203302106516224, -2.344858156028369], [0.36742404637441123, -2.3886054421768708], [0.40461156254852226, -2.4141156462585034], [0.36387868122767975, -2.375], [0.3393199109776927, -2.348404255319149]]
Run Code Online (Sandbox Code Playgroud)

现在,我计算从任何一点到帕累托边境的距离,如下所示:

def dominates(row, rowCandidate):
return all(r >= rc for r, rc in zip(row, rowCandidate))

def dist2Pareto(pareto,candidate):
    listDist = []

    dominateN = 0
    dominatePoss = 0
    if len(pareto) >= 2:
        for i in pareto:
            if i != candidate:
                dominatePoss += 1
                dominate = dominates(candidate,i)
                if dominate == True:
                    dominateN += 1
                listDist.append(np.linalg.norm(np.array(i)-np.array(candidate)))

        listDist.sort()

        if dominateN == …
Run Code Online (Sandbox Code Playgroud)

python interpolation numpy

5
推荐指数
1
解决办法
212
查看次数

计算到凸包的距离

我正在使用scipy 的ConvexHull类为一组点构造凸包。我对计算新点P与凸包的最小距离的方法感兴趣。

在互联网的帮助下,我自己做了一些调整,我想出了这个公式来计算点P或一组点凸包面的距离:

np.max(np.dot(self.equations[:, :-1], points.T).T + self.equations[:, -1], axis=-1)
Run Code Online (Sandbox Code Playgroud)

对于二维凸包,上面的方程将得出以下图:

到凸包的距离

正如您所看到的,结果对于凸包内的点来说非常好并且正确(这里的距离是负数,需要乘以-1)。对于最接近小平面的点也是正确的,但对于最接近凸包顶点的点则不正确。(我用虚线标记了这些区域)对于这些点,正确的最小距离将是到凸包顶点的最小距离。

如何区分最接近面或最接近顶点的点,以正确计算点P或n 维空间(至少 3D)中的一组点到凸包的最小距离?

python numpy distance scipy convex-hull

5
推荐指数
1
解决办法
3725
查看次数

使用 Scipy 在凸包上找到一个点的投影

从一组点来看,我得到了scipy.spatial带有Delaunay或的凸包ConvexHull(来自 qhull 库)。现在我想将这个凸包外的点投影到船体上(即船体上与外部点距离最小的点)。

这是我到目前为止的代码:

from scipy.spatial import Delaunay, ConvexHull
import numpy as np

hu = np.random.rand(10, 2) ## the set of points to get the hull from
pt = np.array([1.1, 0.5]) ## a point outside
pt2 = np.array([0.4, 0.4]) ## a point inside
hull = ConvexHull(hu) ## get only the convex hull
#hull2 = Delaunay(hu) ## or get the full Delaunay triangulation

import matplotlib.pyplot as plt
plt.plot(hu[:,0], hu[:,1], "ro") ## plot all points
#plt.triplot(hu[:,0], …
Run Code Online (Sandbox Code Playgroud)

python delaunay scipy qhull

4
推荐指数
1
解决办法
2979
查看次数

从一组最接近直线的点中找到点的最快算法是什么?

我有:
-一组已知大小的点(在我的情况下,只有6个点)
-一条以x = s + t * r为特征的线,其中x,s和r是3D矢量

I need to find the point closest to the given line. The actual distance does not matter to me.

I had a look at several different questions that seem related (including this one) and know how to solve this on paper from my highschool math classes. But I cannot find a solution without calculating every distance, and I am sure there has to be a better/faster way. Performance is absolutely crucial …

c++ performance linear-algebra computational-geometry

4
推荐指数
1
解决办法
146
查看次数

如何计算C,C#/ .NET 2.0或Java中所有情况下点和线段之间的最短2D距离?

可能重复:
点和线段之间的最短距离

我正在寻找一种在所有情况下计算最小距离的方法.我找到的解决方案的问题是:

  1. 带有图形概念图的解决方案显示点始终与线段垂直,因此它"在线段的端点之间".我的几何技能太可怕了,所以我无法验证这些解决方案是否适用于所有情况.

  2. 算法解决方案是:使用fortran或其他语言我不完全理解,b:被人们标记为不完整,c:调用未以任何方式描述的方法/函数(被认为是微不足道的).

2 a,b和c的好例子是

点与线段之间的最短距离

我将2D线段作为双型坐标对(x1,y1),(x2,y2)并指向双型坐标(x3,y3).C#/ Java/C解决方案都很受欢迎.

感谢您的回答和BR:Matti

c# geometry

3
推荐指数
2
解决办法
4万
查看次数

从CGPoint到段的最短距离

我一直在尝试将Douglas-Peucker算法应用到我的代码中,我能够将伪代码转换为Swift,除了shortestDistanceToSegment函数.只有我能找到的Swift版本才能在这里得到解答,但我不明白它实际上是做什么的.

我需要一个函数,它获得三个点作为参数(点和线的两端)并返回CGPoint和线段之间的最短距离.关于代码做什么(和为什么)的一些解释很好但不是必要的.

line cgpoint swift

3
推荐指数
1
解决办法
1238
查看次数

如何找到最接近一个点的矩形

如果我System.Drawing.Rectangle在画布和一个上有两个对象,计算哪个( 的任何部分,而不仅仅是它的)最接近那个Point最佳方法是什么?RectangleRectangleLocation PointPoint

一个单元测试的例子:

Rectangle one = new Rectangle (0, 0, 10, 10);

Rectangle two = new Rectangle (20, 20, 10, 10);

Point point = new Point(14, 14);

Rectangle actual = ClosestToPoint(point, one, two);

// should be closer to one since one's bottom right is at (10, 10)
Assert.That(actual, Is.SameAs(one));

// method to write
public Rectangle ClosestToPoint(Point p, params Rectangle[] rectangles) { } 
Run Code Online (Sandbox Code Playgroud)

c# geometry system.drawing

2
推荐指数
1
解决办法
5085
查看次数

几何 - 计算点到线的距离

我想计算一个点与由 2 个点定义的线的距离。

我正在使用 javascript,这就是我使用维基百科的想法:https : //en.wikipedia.org/wiki/Distance_from_a_point_to_a_line

function distance(point1, point2, x0, y0) {
    return ((Math.abs((point2.y - point1.y) * x0 - 
                     (point2.x - point1.x) * y0 + 
                     point2.x * point1.y - 
                     point2.y * point1.x)) /
            (Math.pow((Math.pow(point2.y - point1.y, 2) + 
                       Math.pow(point2.x - point1.x, 2)), 
                      0.5)));
}
Run Code Online (Sandbox Code Playgroud)

问题是它似乎不准确,因为如果我输入这些参数:

alert(distance({ x: 1, y: 1 }, { x: 2, y: 2 }, 1, 0));

它返回1/sqrt(2)而不是返回1(这是点(1, 0)和点之间的线之间的距离(1, 1)

编辑:我知道上面的代码没有做我想要它做的。它从一个点计算到一条由 2 点表示的线,但该线是无限的(我想要更像一个有 2 个端点的向量)

我在这里找到了答案

javascript math geometry

2
推荐指数
1
解决办法
1346
查看次数