Syntax
len=CPLlength(CPL)
Input Parameter
Output Parameter
Examples
CPLlength(PLsquare(10))
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 calculates the boundary length of a Closed Polygon List (CPL).
Input Parameters
- CPL: A matrix where each row represents a vertex of the polygon, with the first column as the x-coordinate and the second column as the y-coordinate.
Output Results
- len: The length of the contour line of the polygon.
Algorithm Steps
- Create a polyshape object using the x and y coordinates from the CPL matrix:
ps=polyshape(CPL(:,1),CPL(:,2));
- Calculate the perimeter of the polyshape object:
len=ps.perimeter;
- If the calculated length is zero, perform the following steps:
- Calculate the cumulative sum of distances between consecutive vertices using the
VLdistance
function: l=cumsum(VLdistance(CPL));
- Set
len
to the last element of the cumulative sum: len=l(end);
- If the first and last vertices of the CPL are not equal, divide the length by 2:
if ~isequal(CPL(1,:),CPL(end,:)); len=len/2; end;
Example
To calculate the length of a square with side length 10:
CPLlength(PLsquare(10))
Algorithm explaination created using ChatGPT on 2025-08-18 22:39. (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