Syntax
NPL=PLofCPL(CPL)
Input Parameter
CPL : | | Closed polygon list with unclear closing condition |
Output Parameter
NPL : | | Closed polygon list with open polygons |
Examples
Try
PLofCPL([PLcircle(5);NaN NaN;PLcircle(3)]) % There are no changes
PLofCPL(CPLsample(7)) % remove the closing lines
PLofCPL(VLaddz(CPLsample(7))) % Now try with VL
Copyright 2017-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth
Algorithm (Workflow)
This function, PLofCPL
, is designed to convert a closed polygon list (CPL) into a nested polygon list (NPL) with open polygons. It is particularly useful when CPLs are extruded to solids. The function handles contours separated by NaN NaN, ensuring that the resulting polygons are open.
Input Parameters
- CPL: A closed polygon list with an unclear closing condition. It may have the first point repeated at the end or not.
Output Results
- NPL: A closed polygon list with open polygons, where each polygon is separated by NaN NaN.
Algorithm Steps
- Identify the indices where NaN NaN separates the polygons in the CPL using
find(isnan(CPL(:,1)))
.
- Initialize an index array
a
to mark the start and end of each polygon, including the beginning and end of the CPL.
- Initialize
NPL
as a zero matrix with the same size as CPL
.
- Iterate over each polygon segment defined by
a
:
- Calculate the number of points
ni
in the current polygon segment.
- If the first and last points of the segment are identical, reduce
ni
by one to remove the closing point.
- Copy the open polygon segment into
NPL
.
- Insert NaN NaN to separate polygons in
NPL
.
- Trim
NPL
to remove any unused preallocated space.
- If no output argument is specified, plot the resulting
NPL
and the original CPL
for visual comparison.
Example Usage
PLofCPL([PLcircle(5);NaN NaN;PLcircle(3)])
: No changes are made as the polygons are already open.
PLofCPL(CPLsample(7))
: Removes the closing lines from the polygons.
PLofCPL(VLaddz(CPLsample(7)))
: Demonstrates the function with a vertex list (VL).
Algorithm explaination created using ChatGPT on 2025-08-19 07:42. (Please note: No guarantee for the correctness of this explanation)
Last html export of this page out of FM database by TL: 2025-09-21