cutpolygon

版本 1.1.0.0 (5.4 KB) 作者: Jasper Menger
Cut alias slice alias split a 2D surface polygon by a line, and remove the specified part.
1.3K 次下载
更新时间 2010/1/7

查看许可证

CUTPOLYGON - Split a 2D polygon by a line, and remove one of the sides

Use CUTPOLYGON to cut alias intersect alias split alias slice a polygon P
(being a series of connected X,Y coordinates) with a line L (defined by
two points), removing a specified side s. L can serve as a bottom limit
('B'), top limit ('T'), left limit ('L'), or right limit ('R').

Syntax:
Pc = CUTPOLYGON(P, L, s, doSplit, doPlot, doTable)

Demo (cut random regular polygon with random line):
CUTPOLYGON demo

Inputs:
P Polygon coordinates [X, Y]
L Line defined by two coordinates [x1, y1; x2, y2]
s What side to remove, character or integer

Optional switches:
doSplit Add intermediate NaN entries if the polygon is split into non-connected parts (default false)
doPlot Plot original and cut polygon plus line (default false)
doTable Tabulate intersection and validity per polygon segment (default false)

Side options:
1 / B = bottom remove parts Y < intersection
2 / T = top remove parts Y > intersection
3 / L = left remove parts X < intersection
4 / R = right remove parts X > intersection

Finding the intersection:
http://en.wikipedia.org/wiki/Line-line_intersection

Output:
- Pc is the polygon post-cut [X, Y]
- Pc can be shorter than P (points are removed)
- Pc can contain intermediate NaN entries if doSplit is true

Version history (recent to ancient):
Jan 2010, Dominik Brands, fixed pure horizontal/vertical limit bug
Apr 2009, Jasper Menger , creation

引用格式

Jasper Menger (2024). cutpolygon (https://www.mathworks.com/matlabcentral/fileexchange/24449-cutpolygon), MATLAB Central File Exchange. 检索来源 .

MATLAB 版本兼容性
创建方式 R13
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Elementary Polygons 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
版本 已发布 发行说明
1.1.0.0

Fixed bug for pure horizontal/vertical limits, as suggested by Dominik Brands.

1.0.0.0