Geometric Tests¶
Defines a number of functions to test interactions between various forms data types.
-
pyrr.geometric_tests.
point_closest_point_on_line
(*args, **kwargs)[source]¶ 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
(*args, **kwargs)[source]¶ 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
(*args, **kwargs)[source]¶ 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
(*args, **kwargs)[source]¶ 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
(*args, **kwargs)[source]¶ 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: 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
(*args, **kwargs)[source]¶ Calculates the intersection point of a point and a line.
Performed by checking if the cross-product of the point relative to the line is 0.
-
pyrr.geometric_tests.
point_intersect_line_segment
(*args, **kwargs)[source]¶ 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
(*args, **kwargs)[source]¶ 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
(*args, **kwargs)[source]¶ Check if rays are coincident.
Rays must not only be parallel to each other, but reside along the same vector.
Parameters: ray1, ray2 (numpy.array) – The rays to check. Return type: boolean Returns: Returns True if the two rays are co-incident.
-
pyrr.geometric_tests.
ray_intersect_aabb
(*args, **kwargs)[source]¶ 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
(*args, **kwargs)[source]¶ 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
(*args, **kwargs)[source]¶ 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: Returns: Intersection points as a list of points.
-
pyrr.geometric_tests.
ray_parallel_ray
(*args, **kwargs)[source]¶ Checks if two rays are parallel.
Parameters: ray1, ray2 (numpy.array) – The rays to check. Return type: boolean Returns: Returns True if the two rays are parallel.
-
pyrr.geometric_tests.
sphere_does_intersect_sphere
(*args, **kwargs)[source]¶ 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
(*args, **kwargs)[source]¶ 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: 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.