# Geometric Tests

Defines a number of functions to test interactions between various forms data types.

pyrr.geometric_tests.point_closest_point_on_line(point, line)

  Calculates the point on the line that is closest to the specified point.

  Parameters:

    - point (numpy.array) – The point to check with.

    - line (numpy.array) – The line to check against.

  Return type:

    numpy.array

  Returns:

    The closest point on the line to the point.

pyrr.geometric_tests.point_closest_point_on_line_segment(point, segment)

  Calculates the point on the line segment that is closest to the specified point.

  This is similar to point_closest_point_on_line, except this is against the line segment of finite length. Whereas point_closest_point_on_line checks against a line of infinite length.

  Parameters:

    - point (numpy.array) – The point to check with.

    - line_segment (numpy.array) – The finite line segment to check against.

  Return type:

    numpy.array

  Returns:

    The closest point on the line segment to the point.

pyrr.geometric_tests.point_closest_point_on_plane(point, pl)

  Calculates the point on a plane that is closest to a point.

  Parameters:

    - point (numpy.array) – The point to check with.

    - plane (numpy.array) – The infinite plane to check against.

  Return type:

    numpy.array

  Returns:

    The closest point on the plane to the point.

pyrr.geometric_tests.point_closest_point_on_ray(point, ray)

  Calculates the point on a ray that is closest to a point.

  Parameters:

    - point (numpy.array) – The point to check with.

    - ray (numpy.array) – The ray to check against.

  Return type:

    numpy.array

  Returns:

    The closest point on the ray to the point.

pyrr.geometric_tests.point_height_above_plane(point, pl)

  Calculates how high a point is above a plane.

  Parameters:

    - point (numpy.array) – The point to check.

    - plane (numpy.array) – The plane to check.

  Return type:

    float

  Returns:

    The height above the plane as a float. The value will be negative if the point is behind the plane.

pyrr.geometric_tests.point_intersect_line(point, line)

  Calculates the intersection point of a point and aline.

  Performed by checking if the cross-product of the point relative to the line is 0.

pyrr.geometric_tests.point_intersect_line_segment(point, line)

  Calculates the intersection point of a point and a line segment.

  Performed by checking if the cross-product of the point relative to the line is 0 and if the dot product of the point relative to the line start AND the end point relative to the line start is less than the segment’s squared length.

pyrr.geometric_tests.point_intersect_rectangle(point, rect)

  Calculates the intersection point of a point and a 2D rectangle.

  For 3D points, the Z axis will be ignored.

  Returns:

    Returns True if the point is touching

  or within the rectangle.

pyrr.geometric_tests.ray_coincident_ray(ray1, ray2)

  Check if rays are coincident.

  Rays must not only be parallel to each other, but reside along the same vector.

  Parameters:

    ray2 (numpy.array ray1,) – The rays to check.

  Return type:

    boolean

  Returns:

    Returns True if the two rays are co-incident.

pyrr.geometric_tests.ray_intersect_aabb(ray, aabb)

  Calculates the intersection point of a ray and an AABB

  Parameters:

    - ray1 (numpy.array) – The ray to check.

    - aabb (numpy.array) – The Axis-Aligned Bounding Box to check against.

  Return type:

    numpy.array

  Returns:

    Returns a vector if an intersection occurs. Returns None if no intersection occurs.

pyrr.geometric_tests.ray_intersect_plane(ray, pl, front_only=False)

  Calculates the intersection point of a ray and a plane.

  Parameters:

    - ray (numpy.array) – The ray to test for intersection.

    - pl (numpy.array) – The plane to test for intersection.

    - front_only (boolean) – Specifies if the ray should

  only hit the front of the plane. Collisions from the rear of the plane will be ignored.

  :return The intersection point, or None if the ray is parallel to the plane. Returns None if the ray intersects the back of the plane and front_only is True.

pyrr.geometric_tests.ray_intersect_sphere(ray, sphere)

  Returns the intersection points of a ray and a sphere. See: https://www.scratchapixel.com/lessons/3d-basic-rendering/minimal-ray-tracer-rendering-simple-shapes/ray-sphere-intersection The ray is defined via the following equation O+tD. Where O is the origin point and D is a direction vector. A sphere is defined as |P−C|^2=R2 where P is the origin and C is the center of the sphere. R is the radius of the sphere.

  Args:

    ray: Ray geometry sphere: Sphere geometry

  Returns:

    list: Intersection points as 3D vector list

  Parameters:

    - ray (numpy.array) – Ray parameter.

    - sphere (numpy.array) – Sphere parameter.

  Return type:

    float

  Returns:

    Intersection points as a list of points.

pyrr.geometric_tests.ray_parallel_ray(ray1, ray2)

  Checks if two rays are parallel.

  Parameters:

    ray2 (numpy.array ray1,) – The rays to check.

  Return type:

    boolean

  Returns:

    Returns True if the two rays are parallel.

pyrr.geometric_tests.sphere_does_intersect_sphere(s1, s2)

  Checks if two spheres overlap.

  Note: This will return True if the two spheres are touching perfectly but sphere_penetration_sphere will return 0.0 as the touch but don’t penetrate.

  This is faster than circle_penetrate_amount_circle as it avoids a square root calculation.

  Parameters:

    - s1 (numpy.array) – The first circle.

    - s2 (numpy.array) – The second circle.

  Return type:

    boolean

  Returns:

    Returns True if the circles overlap. Otherwise, returns False.

pyrr.geometric_tests.sphere_penetration_sphere(s1, s2)

  Calculates the distance two spheres have penetrated into one another.

  Parameters:

    - s1 (numpy.array) – The first circle.

    - s2 (numpy.array) – The second circle.

  Return type:

    float

  Returns:

    The total overlap of the two spheres. This is essentially: r1 + r2 - distance Where r1 and r2 are the radii of circle 1 and 2 and distance is the length of the vector p2 - p1. Will return 0.0 if the circles do not overlap.

pyrr.geometric_tests.vector_parallel_vector(v1, v2)

  Checks if two vectors are parallel.

  Parameters:

    v2 (numpy.array v1,) – The vectors to check.

  Return type:

    boolean

  Returns:

    Returns True if the two vectors are parallel.