CPLisccwinout

by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - CPL/Closed Polygon Lists
Introduced first in SolidGeometry 3.9, Creation date: 2017-05-27, Last change: 2025-09-14

returns which contour has the right orientation wrt shell and orientation

Description

Depending on the outwards level, the orientation of a contour is:
0 = outward = ccw
1 = inward = cw
2 = outward = ccw
3 .....
if length(corr)==sum(corr); the contour is correct

See Also: CPLisccw , CPLsortinout , CPLisccwcorrected , CPLsetallcw

Example Illustration

 missing image of CPLisccwinout(CPL)

Syntax

[corr,cio,ccw]=CPLisccwinout(CPL)

Input Parameter

CPL: Contour polygon list

Output Parameter

corr: true if correct
cio: level of contour (0=most outwards)
ccw: ccw direction

Examples


FCPL=replaceNaN(CPLsample(12),3,flipud(separateNaN(CPLsample(12),3)));
CPLisccwinout(FCPL)
CPLisccwinout(CPLsample(13))




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, CPLisccwinout, determines the orientation of contours in a contour polygon list (CPL) and checks if they are correctly oriented with respect to their level of nesting.

Input Parameters

Output Results

Algorithm Steps

  1. Initialize chng to false. If an additional argument is provided and is not empty, set chng to that argument.
  2. Call CPLsortinout to determine the nesting level of each contour, storing the result in cio.
  3. Call CPLisccw to determine the orientation of each contour, storing the result in ccw.
  4. Calculate corr using the XOR operation between the oddness of cio and ccw. This checks if the contour orientation matches the expected orientation based on its nesting level.
  5. If no output arguments are specified, plot the contours using different colors to indicate their orientation and correctness:
    • Green for counter-clockwise (ccw) contours.
    • Blue for clockwise (cw) contours.
    • Red dashed lines for incorrectly oriented contours.

Example Usage

Example code snippets demonstrate how to use the function with sample data:

FCPL = replaceNaN(CPLsample(12), 3, flipud(separateNaN(CPLsample(12), 3)));
CPLisccwinout(FCPL);
CPLisccwinout(CPLsample(13));
Algorithm explaination created using ChatGPT on 2025-08-19 08:22. (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