Polygon¶
- class acoular.grids.Polygon(x, y)¶
Bases:
object
Create an object representing a general polygon in a 2D plane.
This class allows defining a polygon by specifying the coordinates of its vertices and provides methods for checking whether a set of points lies inside the polygon, or if a point is closer to a side or vertex of the polygon.
- Parameters:
- xarray_like
Array of x-coordinates of the vertices that define the polygon. These coordinates should form a closed shape (i.e., the last point should be the same as the first point).
- yarray_like
Array of y-coordinates of the vertices that define the polygon. These coordinates should correspond to the x-coordinates, forming a closed shape.
- Attributes:
- x
numpy.ndarray
Array of x-coordinates of the polygon vertices.
- y
numpy.ndarray
Array of y-coordinates of the polygon vertices.
- x
- is_inside(xpoint, ypoint, smalld=1e-12)¶
Check if a point or set of points are inside the polygon.
- Parameters:
- xpoint
float
or array_like Array of x-coordinates of the points to be tested.
- ypoint
float
or array_like Array of y-coordinates of the points to be tested.
- smalld
float
, optional Tolerance used for floating point comparisons when checking if a point is exactly on a polygon’s edge. The default value is
1e-12
.
- xpoint
- Returns:
float
or array_likeThe distance from the point to the nearest point on the polygon. The values returned have the following meanings: -
mindst < 0
: Point is outside the polygon. -mindst = 0
: Point is on an edge of the polygon. -mindst > 0
: Point is inside the polygon.
Notes
The method uses an improved algorithm based on Nordbeck and Rydstedt for determining whether a point is inside a polygon [17].