CPLcircshift
by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - CPL/Closed Polygon Lists
Introduced first in SolidGeometry 2.0, Creation date: 2014-12-05, Last change: 2025-09-14
shifts & closes a PL. First point is [minx miny]
Description
Attention the length of the NPL can be increased to add the first point as last point.
cl = false => CPL may be longer than PL
CL = true => CPL is PL if the input argument was PL
See Also: circshiftCPL
Example Illustration
Syntax
[NPL,k]=CPLcircshift(PL,[cl])
Input Parameter
PL: | | Original PL or CPL |
cl: | | constant length; default is false |
Output Parameter
NPL: | | Shifted and CPL |
k: | | shiftindex |
Copyright 2014-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, CPLcircshift, is designed to shift and close a polygon list (PL) such that the first point is the minimum x and y coordinate. It is part of the SolidGeometry library.
Input Parameters
- PL: The original polygon list, which can be either open or closed.
- cl: A boolean indicating whether the output should maintain a constant length. The default value is
false.
Output Results
- NPL: The shifted and closed polygon list.
- k: The index indicating the shift position.
Algorithm Steps
- Determine the number of points in the polygon list
PL using size(PL,1).
- Set
cl to false by default. If a second argument is provided and is not empty, set cl to that value.
- Check if
PL contains NaN values. If so, throw an error as NaN is not allowed.
- If the first and last points of
PL are the same, remove the last point to avoid duplication.
- Find the minimum x-coordinate and the corresponding minimum y-coordinate to determine the starting point
mp.
- Find the index
k of the point mp in PL. If there are multiple indices, throw an error indicating duplicate points.
- Use
circshift to shift PL such that mp becomes the first point. Append the first point to the end to close the polygon.
- If
cl is true and the new polygon list NPL is longer than the original, remove the last point to maintain the original length.
Algorithm explaination created using ChatGPT on 2025-08-19 01:09. (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