pyroomacoustics.geometry module

pyroomacoustics.geometry.area(corners)

Computes the signed area of a 2D surface represented by its corners.

Parameters:corners – (np.array 2xN, N>2) list of coordinates of the corners forming the surface
Returns:(float) area of the surface positive area means anti-clockwise ordered corners. negative area means clockwise ordered corners.
pyroomacoustics.geometry.ccw3p(p1, p2, p3)

Computes the orientation of three 2D points.

Parameters:
  • p1 – (ndarray size 2) coordinates of a 2D point
  • p2 – (ndarray size 2) coordinates of a 2D point
  • p3 – (ndarray size 2) coordinates of a 2D point
Returns:

(int) orientation of the given triangle 1 if triangle vertices are counter-clockwise -1 if triangle vertices are clockwise 0 if vertices are collinear

Ref:

https://en.wikipedia.org/wiki/Curve_orientation

pyroomacoustics.geometry.intersection_2D_segments(a1, a2, b1, b2)

Computes the intersection between two 2D line segments.

This function computes the intersection between two 2D segments (defined by the coordinates of their endpoints) and returns the coordinates of the intersection point. If there is no intersection, None is returned. If segments are collinear, None is returned. Two booleans are also returned to indicate if the intersection happened at extremities of the segments, which can be useful for limit cases computations.

Parameters:
  • a1 – (ndarray size 2) coordinates of the first endpoint of segment a
  • a2 – (ndarray size 2) coordinates of the second endpoint of segment a
  • b1 – (ndarray size 2) coordinates of the first endpoint of segment b
  • b2 – (ndarray size 2) coordinates of the second endpoint of segment b
Returns:

(tuple of 3 elements) results of the computation (ndarray size 2 or None) coordinates of the intersection point (bool) True if the intersection is at boundaries of segment a (bool) True if the intersection is at boundaries of segment b

pyroomacoustics.geometry.intersection_segment_plane(a1, a2, p, normal)

Computes the intersection between a line segment and a plane in 3D.

This function computes the intersection between a line segment (defined by the coordinates of two points) and a plane (defined by a point belonging to it and a normal vector). If there is no intersection, None is returned. If the segment belongs to the surface, None is returned. A boolean is also returned to indicate if the intersection happened at extremities of the segment, which can be useful for limit cases computations.

Parameters:
  • a1 – (ndarray size 3) coordinates of the first endpoint of the segment
  • a2 – (ndarray size 3) coordinates of the second endpoint of the segment
  • p – (ndarray size 3) coordinates of a point belonging to the plane
  • normal – (ndarray size 3) normal vector of the plane
Returns:

(tuple of 2 elements) results of the computation (ndarray size 3 or None) coordinates of the intersection point (bool) True if the intersection is at boundaries of the segment

pyroomacoustics.geometry.intersection_segment_polygon_surface(a1, a2, corners_2d, normal, plane_point, plane_basis)

Computes the intersection between a line segment and a polygon surface in 3D.

This function computes the intersection between a line segment (defined by the coordinates of two points) and a surface (defined by an array of coordinates of corners of the polygon and a normal vector) If there is no intersection, None is returned. If the segment belongs to the surface, None is returned. Two booleans are also returned to indicate if the intersection happened at extremities of the segment or at a border of the polygon, which can be useful for limit cases computations.

Parameters:
  • a1 – (ndarray size 3) coordinates of the first endpoint of the segment
  • a2 – (ndarray size 3) coordinates of the second endpoint of the segment
  • corners – (ndarray size 3xN, N>2) coordinates of the corners of the polygon
  • normal – (ndarray size 3) normal vector of the surface
Returns:

(tuple of 3 elements) results of the computation (ndarray size 3 or None) coordinates of the intersection point (bool) True if the intersection is at boundaries of the segment (bool) True if the intersection is at boundaries of the polygon

pyroomacoustics.geometry.is_inside_2D_polygon(p, corners)

Checks if a given point is inside a given polygon in 2D.

This function checks if a point (defined by its coordinates) is inside a polygon (defined by an array of coordinates of its corners) by counting the number of intersections between the borders and a segment linking the given point with a computed point outside the polygon. A boolean is also returned to indicate if a point is on a border of the polygon (the point is still considered inside), which can be useful for limit cases computations.

Parameters:
  • p – (ndarray size 2) coordinates of the point
  • corners – (ndarray size 2xN, N>2) coordinates of the corners of the polygon
Returns:

(tuple of 2 elements) results of the computation (bool) True if the point is inside (bool) True if the intersection is at boundaries of the polygon

pyroomacoustics.geometry.side(p, p0, vector)

Compute on which side of a given point an other given point is according to a vector.

Parameters:
  • p – (ndarray size 2 or 3) point to be tested
  • p0 – (ndarray size 2 or 3) origin point
  • vector – (ndarray size 2 or 3) directional vector
Returns:

(int) direction of the point 1 : p is at the side pointed by the vector 0 : p is in the middle (on the same line as p0) -1 : p is at the opposite side of the one pointed by the vector