cutpolygon
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
Cite As
Jasper Menger (2024). cutpolygon (https://www.mathworks.com/matlabcentral/fileexchange/24449-cutpolygon), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.