档案交换一周

我们最好的用户提交

从点到多线或多边形的距离

肖恩本周的选择是Distance from points to polyline or polygon经过Michael Yoshpe

I recently had a problem where I was trying to identify which corners of a property lot were abutting a street.

以下是一个例子;多边形存储在相对较新的polyshape班级。

加载polyshapes.matp(1) = plot(lot,“ faceColor”,,,,"b");holdonp(2)=情节(街,“ faceColor”,[0.5 0.5 0.5]);Xticks([])yticks([])传奇([[[[[[]“很多”“街道”])

我看着的方法polyshape并首先想到最近的佛教徒would be the correct way to do it. I.e. given the nearest vertex for each point, calculate the distance to it and apply a threshold.

NIDX =最近的Vertex(Street,Lot.vertices);p(3)=情节(street.vertices(nidx,1),street.vertices(nidx,2),"r*",,,,“显示名称”,,,,“街上最近的顶点”);

起初这看起来不错,但是让我们放大:

加载Zoomlimits.matXlim(Xlimits)Ylim(Ylimits)

最近的顶点只在看一条街道的顶点。沿边界的顶点之间可能存在很长的距离,因此它可以返回绝对没有意义的人,例如街的远端。我实际上需要的是从批次顶点到街道边界的距离。

不幸的是,在计算几何学意义上没有明显的多层方法。我可以使用linspace向每个边界添加数千点以提高顶点的数量最近的佛教徒可以得到“关闭enough” but that seemed like a less than optimal means for solving this problem.

我搜索过MATLAB答案并遇到this answer来自Mathworks的技术支持。金宝app这提供了找到与线路的距离的手段。一个人可以在街道的所有边界上循环,计算最短的距离,然后将最小值保持在末端。相反,我搜索了文件交换,发现了迈克尔的p_poly_distfunction. It does exactly what I need (though requires looping over vertices instead of boundaries).

%从街道上抓住边界。[xbnd,ybnd] =边界(街);%循环在批次顶点上,计算到街道边界的最短距离。为了ii = size(lot.Vertices, 1):-1:1 dists(ii, 1) = p_poly_dist(lot.Vertices(ii, 1), lot.Vertices(ii, 2), xbnd, ybnd);结尾%的顶点在边框上,如果在阈值或街道内部。阈值= 2;onborder =(dists <阈值)|Isinterior(街,lot.vertices);删除(p(p(3))图(lot.vertices(Onborder,1),lot.vertices(Onborder,2),"mp",,,,“显示名称”,,,,"On Street") xlimautoylimauto

我也想大喊大叫Point To Line Distance经过Rik Wisselink- 向技术支持提供了输入检查,并将其扩展到多个点上。金宝app我没有为此使用它,因为我不需要3D,并且在边界上循环效果比循环循环到顶点要多得多。

Comments

If you want this functionality in base MATLAB, please contact MathWorks Tech Support and add your vote by letting them know this answer was useful!

Give it a try and let us know what you thinkhere或留下一个评论为了Michael.

与Matlab®R2019A一起出版

|
  • 打印
  • 发送电子邮件

Comments

要发表评论,请单击here登录您的数学帐户或创建一个新帐户。