PLofCPL
by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - CPL/Closed Polygon Lists
Introduced first in SolidGeometry 3.4, Creation date: 2017-02-01, Last change: 2025-09-14
converts a nested CPL into a nested PL
Will be removed (2025-09-21): Use 'openCPL' instead
Description
This function is useful if CPLS are extruded to solids. CPLs are contours that are separted by NaN NaN. Nevertheless; sometimes the first point is doubled at the end, somethimes not. This function returns CPLs that are separated by NaN NaN but the point lists are open
Works with PL and VL
See Also: , CPLofPL
, CPLofPLcontour
Example Illustration
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