paralleldomain.utilities.geometry¶
- calculate_triangle_area(triangles)¶
Calculates sizes of an array of triangles defined by their three verticies :type triangles:
ndarray
:param triangles: n x 3 x 2 array containing the 3 vertices of each triangle
- convex_hull_2d(points_2d, closed=False)¶
Takes a list of 2d points and returns their convex hull
- Parameters:
- Return type:
- Returns:
n x 2 array of the 2d points defining the convex hull
- convex_hull_2d_as_mask(points_image_2d, width, height)¶
Takes a list of 2d points and returns their convex hull in the form of a filled in mask
- Parameters:
points_image_2d (
ndarray
) – n x 2 array of the 2d points (in image space) we wish to find the convex hull ofwidth (
int
) – The width of the image space on which the points exist and the width of the returned image containing the convex hull maskheight (
int
) – The height of the image space on which the points exist and the height of the returned image containing the convex hull mask
- Return type:
- Returns:
height x width array containing the mask of the calculated convex hull
- decompose_polygon_into_triangles(vertices)¶
Takes an area defined by a 2D polygon and decomposes it into triangles using the Ear Clipping Method.
- interpolate_points(points, num_points, flatten_result=True)¶
Takes a list of points and interpolates a number of additional points inbetween each point pair.
- Parameters:
points (
ndarray
) – Array of consecutive pointsnum_points (
int
) – Every start point per pair will result in num_points points after interpolation.flatten_result (
bool
) – If False will return interpolated points, where first axis groups by each input point pair; else returns flat list of all points. Default: True
- Return type:
- Returns:
Array of points with linearly interpolated values inbetween.
- is_point_in_polygon_2d(polygon, point, include_edge=True)¶
Checks if a point lies inside a polygon shape.
- Parameters:
polygon (
Union
[ndarray
,List
[Union
[List
[float
],Tuple
[float
,float
]]]]) – Array of consecutive points that form a polygonpoint (
Union
[ndarray
,List
[float
],Tuple
[float
,float
]]) – 2D point coordinates to be tested if they lie in the specified polygoninclude_edge (
bool
) – If point is considered inside if lying on the edge or not. Default: True
- Return type:
- Returns:
True if point in polygon, otherwise False
- random_point_in_triangle(triangle, random_seed)¶
Calculates a random point in a given triangle. Ensuring that the random points are roughly uniformly distributed :type triangle:
ndarray
:param triangle: 3 x 2 array containing the x,y position of the triangle’s verticies :type random_seed:int
:param random_seed:
- random_point_within_2d_polygon(edge_2d, random_seed, num_points=1)¶
Returns a random point within a polygon. Note that this returns a z value of 0 :type edge_2d:
ndarray
:param edge_2d: n x 2 array containing the 2d coordinates of the verticies of the polygon :type random_seed:int
:param random_seed: random seed - will be overridden if randomize_point_selection is set to True :type num_points:int
:param num_points: Number of points to spawn
- simplify_polyline_2d(polyline, supporting_points_indices=None, approximation_error=0.1)¶
Takes a 2D polyline and simplifies its shape while allowing for a specified error.
- Parameters:
polyline (
Union
[ndarray
,List
[Union
[List
[float
],Tuple
[float
,float
]]]]) – 2D Polyline that should be simplified.supporting_points_indices (
Optional
[List
[int
]]) – An optional list of vertices of the polyline that need to be kept during simplification.approximation_error (
float
) – The maximum error that’s allowed to be introduced during simplification.
- Return type:
- Returns:
A simplified version of the input polyline, or the input polyline if no simplification could be done.