# 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) –

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:
• polygon (`Union`[`ndarray`, `List`[`Union`[`List`[`float`], `Tuple`[`float`, `float`]]]]) – Array of consecutive points that form a polygon

• point (`Union`[`ndarray`, `List`[`float`], `Tuple`[`float`, `float`]]) – 2D point coordinates to be tested if they lie in the specified polygon

• include_edge (`bool`) – If point is considered inside if lying on the edge or not. Default: True

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:
• triangle (ndarray) –

• random_seed (int) –

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.