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
- VL: A vertex list representing the contour. The contour must be closed, meaning the start and end points should be the same.
- PL: A list of points to check against the contour.
Output
- tp: An array where each element is +1 if the point is inside the contour, -1 if outside, and 0 if on the contour.
Algorithm Steps
- 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
.
- If multiple contours are detected, the function iterates over each contour, calling itself recursively to determine the position of points relative to each contour.
- If no NaN values are present, the function proceeds with the single contour.
- Ensure the contour is closed by appending the first vertex to the end of the list.
- Initialize an array
tp
to store the results for each point in PL
.
- For each point in
PL
, initialize a variable t
to -1.
- Iterate over each edge of the contour and use the
crosstest
function to determine the relative position of the point to the edge.
- Multiply the result of
crosstest
with t
to update the position status.
- Store the final value of
t
in the tp
array for each point.
- 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