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

Return type:

ndarray

Returns:

n x 1 array of triangle sizes

Parameters:

triangles (ndarray) –

convex_hull_2d(points_2d, closed=False)

Takes a list of 2d points and returns their convex hull

Parameters:
  • points_2d (ndarray) – n x 2 array of the 2d points we wish to find the convex hull of

  • closed (bool) – True if the returned convex hull should be closed (first point is same as last point on hull). False if returned convex hull should be open

Return type:

ndarray

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 of

  • width (int) – The width of the image space on which the points exist and the width of the returned image containing the convex hull mask

  • height (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:

ndarray

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.

Parameters:

vertices (ndarray) – n x 2 array containing the 2d coordinates of the vertices of the polygon

Return type:

ndarray

Returns:

n x 3 x 2 array containing the 3 vertices of each n triangle

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 points

  • num_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:

ndarray

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:
Return type:

bool

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:

Return type:

ndarray

Returns:

2 x 1 array of x,y position of randomly selected point in each triangle

Parameters:
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

Return type:

ndarray

Returns:

num_points x 2 array containing the x,y positions of the point(s)

Parameters:
  • edge_2d (ndarray) –

  • random_seed (int) –

  • num_points (int) –

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:

ndarray

Returns:

A simplified version of the input polyline, or the input polyline if no simplification could be done.