线段与多边形的交点 [英] Intersection of segment with polygon

查看:700
本文介绍了线段与多边形的交点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在MATLAB中创建一个函数来执行以下任务:

I have to create a function in MATLAB that performs the following task:

输入:

p 多边形

p = [x1,y1; x2,y2; x3,y3; x4,y4 ...]

p = [x1,y1; x2,y2; x3,y3; x4,y4...]

s 结构,其段从A到B

s struct with the segment from A to B

s = struct('A',[x,y],'B'[u,w])

s = struct('A',[x,y],'B'[u,w])

返回:

1)一个整数,指示线段和多边形之间有多少个相交点(例如0,1,2)

1) An integer indicating how many intersections there are between the segment and the polygon (e.g., 0,1,2)

2)从A到B的新线段,其中A是输入线段的第一个交点或起点,而B是线段输入的交点的第二点或终点.

2) A new segment from A to B, where A is the first intersection or the initial point of the input segment and B the second point of the intersection or the last point of the segment input.

我对使用功能 inpolygon 的想法有所了解.我一直在阅读如何使用此功能,并且知道要使用该功能,我应该提供查询点和多边形顶点的坐标.它将返回1或0,具体取决于它是否在内部.

I have an idea on how to do it by using the function inpolygon. I have been reading how to use this function, and know that to use that, I should provide a query point and the coordinates of the polygon vertices. It will return 1 or 0 depending on whether it is inside or not.

我的问题是,如何获取正好位于边界内的线段的查询点(如果线段与它相交)?

My question is, how can I get the query point of the segment that is placed exactly in the boundary (in the case that the segment intersects with it)?

推荐答案

如果安装了映射工具箱,则可以使用多边形相交" :

If you have the Mapping Toolbox installed, you could use polyxpoly. As this is a rather basic problem, there are quite a few free MATLAB-codes out there on the File Exchange. Here is what I found for the search term 'polygon intersect':

找到两个2D多边形的边的相交点,这是跟踪新闻组讨论的简单功能

Find the intersection points of the edges of two 2D polygons, a simple function made to follow up a Newsgroup discussion

  • 曲线相交2 塞巴斯蒂安·霍尔茨(SebastianHölz)

    此文件基于Duane Hanselman的曲线相交"功能.它将功能的范围扩展到可以处理任意线/多边形,这些线/多边形也可能具有垂直线段或x值不增加的线段.

    This file is based on the Curve Intersect function by Duane Hanselman. It extends the scope of the function to handle arbitrary lines / polygons, which may also have vertical segments or segments with non-increasing x-values.

  • 曲线交点,由 NS

    虽然FEX中已经存在一些其他函数来计算 曲线的交点,这段简短的代码被写成 速度是重中之重.整个过程都没有使用循环, 充分利用MATLAB的矢量化功能

    While a few other functions already exist in FEX that compute the intersection points of curves, this short piece of code was written with speed being the highest priority. No loops are used throughout, taking full advantage of MATLAB's vectorization capabilities

  • 快速和鲁棒曲线的交叉点 by Douglas Schwarz

  • Fast and Robust Curve Intersections by Douglas Schwarz

    此函数计算两条曲线相交的(x,y)位置.曲线可以被NaN破坏或具有垂直线段.它也非常快(至少在代表我认为是典型应用程序的数据上).

    This function computes the (x,y) locations where two curves intersect. The curves can be broken with NaNs or have vertical segments. It is also very fast (at least on data that represents what I think is a typical application).

  • geom2d ,作者是 David Legland

  • geom2d by David Legland

    [...]得出新的形状:2条线之间,一条线与一个圆之间的交点,平行线和垂直线

    [...] derive new shapes: intersection between 2 lines, between a line and a circle, parallel and perpendicular lines

  • 这篇关于线段与多边形的交点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆