Syntax
ii=isInteriorofCPL(CPL,PL);
Input Parameter
CPL : | | Vertex list of the contour |
PL : | | Point to check |
Output Parameter
ii : | | +1==inside or on, 0==outside |
Examples
isInteriorofCPL(CPLsample(8)/10,rand(1000000,2));
isInteriorofCPL(PLcircle(1),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 function, isInteriorofCPL
, determines whether a given point is inside or on the boundary of a closed contour in 2D. It is designed for simple closed polygonal lines (CPL) and is optimized for speed compared to other similar functions.
Input Parameters
- CPL: A list of vertices that define the closed contour. It is expected to be an Nx2 matrix where each row represents a vertex with x and y coordinates.
- PL: A list of points to be checked. It is an Mx2 matrix where each row represents a point with x and y coordinates.
Output Results
- ii: A binary indicator where +1 means the point is inside or on the contour, and 0 means the point is outside.
Algorithm Steps
- Determine the number of vertices in the contour (
n1
) and the number of points to check (n2
).
- If there are no points to check (
n2 == 0
), return an empty result.
- Check if the contour has more than 6 vertices, more than 100,000 points to check, or if any vertex coordinate is NaN. If any of these conditions are true:
- Create a polygon shape using the
polyshape
function with the contour vertices.
- Use the
isinterior
function to determine if each point is inside the polygon.
- If the above conditions are not met, use the
insideCPL
function to determine if each point is inside the contour. The result is adjusted to be binary (+1 or 0).
- If no output argument is specified, plot the results:
- Display the contour using
CPLplot
with a black line.
- Plot points inside the contour in green and points outside in red using
PLplot
.
- Adjust the axis to grow by 10% using
BBgrow
.
Algorithm explaination created using ChatGPT on 2025-08-19 01:19. (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