Syntax
CPL=CPLofPLseparatedlines(PL)
Input Parameter
PL : | | List of point [nx2] n is an even integer |
Output Parameter
CPL : | | Pairs separated by nan nan |
Examples
CPLofPLseparatedlines([0 0; 10 0; 20 20 ; 20 40])
Copyright 2022-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, CPLofPLseparatedlines
, is designed to convert a list of 2D point pairs into a closed polygon list (CPL) where each pair is separated by nan nan
. This is useful for visualizing or processing line segments as distinct entities.
Input Parameters
- PL: A list of points in the format [nx2], where n is an even integer. Each row represents a point in 2D space.
Output Results
- CPL: A list of points where each pair from the input is separated by
nan nan
.
Algorithm Steps
- Reshape Input: The input list
PL
is reshaped to a 4-column format using reshape(PL',4,[])'
. This groups the points into pairs.
- Add NaN Separation: A new matrix
NL
is created by appending nan
values to each pair using nan(size(LL,1),2)
. This effectively separates each pair with nan nan
.
- Reshape to Output Format: The matrix
NL
is reshaped back to a 2-column format using reshape(NL',2,[])'
, creating the final CPL.
- Remove Last NaN: The last row, which contains
nan nan
, is removed from CPL
using CPL(1:end-1,:)
.
- Optional Plotting: If no output is requested (
nargout==0
), the function plots the CPL using SGfigure
and PLplot
with red stars and lines.
Example
For example, calling CPLofPLseparatedlines([0 0; 10 0; 20 20; 20 40])
will produce a CPL where each pair of points is separated by nan nan
.
Algorithm explaination created using ChatGPT on 2025-08-18 23:18. (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