insideCPL

by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Analyzing function
Introduced first in SolidGeometry 4.9, Creation date: 2020-01-22, Last change: 2025-09-14

tests whether a point is inside of a closed contour in 2D!

Description

ONLY FOR SINGLE CLOSED CONTOURS
for simple CPL; this function is faster than
+1 means point is inside
-1 means point is outside
0 means point is on the contour

See Also: crosstest , insideCPS , isInteriorofCPL , CPLselectbyP

Example Illustration

 missing image of insideCPL(VL,PL);

Syntax

tp=insideCPL(VL,PL);

Input Parameter

VL: Vertex list of the contour! MUST BE CLOSED OTHERWISE START/END POINTS ARE NOT DETECTED
PL: Point to check

Output Parameter

tp: +1==inside, -1==outside, 0== on the contour

Examples


insideCPL([0 0; 1 0; 1 1; 0 0],rand(1000000,2));




Copyright 2020-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 algorithm determines whether a point is inside, outside, or on a closed contour in 2D space. It is designed for single closed contours and is part of the SolidGeometry library.

Input Parameters

Output

Algorithm Steps

  1. Check if the vertex list VL contains any NaN values. If it does, the function assumes multiple contours are present and separates them using separateNaN.
  2. If multiple contours are detected, the function iterates over each contour, calling itself recursively to determine the position of points relative to each contour.
  3. If no NaN values are present, the function proceeds with the single contour.
  4. Ensure the contour is closed by appending the first vertex to the end of the list.
  5. Initialize an array tp to store the results for each point in PL.
  6. For each point in PL, initialize a variable t to -1.
  7. Iterate over each edge of the contour and use the crosstest function to determine the relative position of the point to the edge.
  8. Multiply the result of crosstest with t to update the position status.
  9. Store the final value of t in the tp array for each point.
  10. If no output argument is specified, plot the contour and points using different colors to indicate their position relative to the contour.
Algorithm explaination created using ChatGPT on 2025-08-19 08:25. (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