intersections_util
Short description
@author: Moritz F P Becker
- pyrid.geometry.intersections_util.any_ray_mesh_intersection_test(origin, dX_O, System)[source]
Tests if their is any intersection of a line segment with the mesh. Returns as soon as the first intersection is detected. The algorithm is based on [5] : Amanatides et al. 1987 “A Fast Voxel Traversal Algorithm for Ray Tracing” Also see [6] : Ericson “Real-Time Collision Detection”, chapter 7.4.2 and 7.7
- Parameters
- originfloat64[3]
Position vector
- dX_Ofloat64[3]
Direction vector
- Systemobject
Instance of System class
- Returns
- boolean
True if any intersection is found.
- pyrid.geometry.intersections_util.edge_intersection_barycentric(u, v, du, dv)[source]
Tests intersection of a line segment with triangle edges in barycentric coordinates and returns the edge index and distance to the edge. Edges must be numbered counter clockwise.
- Parameters
- ufloat64
Barycentric u coordinate
- vfloat64
Barycentric v coordinate
- dufloat64
Barycentric u coordinate of the line segment
- dvfloat64
Barycentric v coordinate of the line segment
- Returns
- tuple(int64, float64)
Edge index, distance to edge
- pyrid.geometry.intersections_util.mesh_inside_box_test(Compartment, System)[source]
Tests if a mesh intersects at some point with the simulation box.
- Parameters
- Compartmentobject
Instance of Compartment class
- Systemobject
Instance of System class
- Returns
- boolean
True if mesh intersects with simulation box.
- pyrid.geometry.intersections_util.point_in_triangle_barycentric(u, v)[source]
Tests if a point given in barycentric coordinates is inside the triangle.
- Parameters
- ufloat64
Barycentric u coordinate
- vfloat64
Barycentric v coordinate
- Returns
- boolean
True if point is inside the triangle.
- pyrid.geometry.intersections_util.point_inside_AABB_test(pos, AABB)[source]
Tests is a point is inside an AABB
- Parameters
- posfloat64[3]
Position vector
- AABBfloat64[2,3]
Array containing the two vector points that represent the lower left and upper right corner of the AABB
- Returns
- boolean
True if point inside AABB
- pyrid.geometry.intersections_util.point_inside_mesh_test(triangle_ids, Mesh, vertices, point, tolerance=1e-06)[source]
Tests if a point is inside or outside a mesh.
- Parameters
- triangle_idsint64[:]
Triangle ids of the mesh
- Mesharray_like
Mesh structured array containing a field ‘triangles’ that keeps the vertex ids of the mesh triangles
- verticesfloat64[:,3]
Mesh vertices
- pointfloat64[3]
Position vector
- Returns
- bolean
True if point is inside mesh.
- pyrid.geometry.intersections_util.point_inside_mesh_test_raycasting(pos, comp_id, System)[source]
Tests if a point id inside or outside a mesh. The algorithm casts a ray from the given point and counts the number of times it intersects with a triangle/the mesh surface. If the ray passes an odd number of triangles, it is in the mesh compartment (see ‘point in polygon problem’). For efficiency, we divide space into cells and do a fast voxel traversal.
- Parameters
- posfloat64[3]
Position vector
- comp_idint64
Compartment index
- Systemobject
Instance of System class
- Returns
- boolean
True if the point is inside the mesh.
- pyrid.geometry.intersections_util.point_inside_triangle_test(pos, triangle_id, System)[source]
Tests if a point is inside a triangle.
- Parameters
- posfloat64[3]
Position vector
- triangle_idint64
Triangle id
- Systemobject
Instance of System class
- Returns
- boolean
True if point is inside triangle, otherwise False.
- pyrid.geometry.intersections_util.ray_mesh_intersection_count(pos, dX, System, cell, time_stamp, comp_id)[source]
Counts the number of times a line segments collides/intersects with a mesh surface. Can be used, e.g., to test whether a point sites inside or outside a mesh if we know that the end point of the line segment is outside the mesh. If the intersection count is odd, the point is located inside the mesh.
- Parameters
- posfloat64[3]
Position vector
- dXfloat64[3]
Direction vector
- Systemobject
Instance of System class
- cellint64
Cell in which to check for ray triangle collisions
- time_stampint64
Each triangle keeps a time stamp that indicates whether the triangle has already been tested for collisions with the current ray. The time stamp is increased every time a new ray is cast.
- comp_idint64
Compartment index
- Returns
- int64
Number of intersections
See also
point_inside_mesh_test2
- pyrid.geometry.intersections_util.ray_mesh_intersection_test(pos, dX, System, cell, t_min, triangle_of_intersection, current_triangle)[source]
Tests if a line segment intersects with a mesh within a given cell by looping over all triangles in the cell and doing a ray triangle collision test.
- Parameters
- posfloat64[3]
Position vector
- dXfloat64[3]
Direction vector
- Systemobject
Instance of System class
- cellint64
Cell in which to check for ray triangle collisions
- t_minfloat64
Current minimum parameterized distance coordinate
- triangle_of_intersectionint64
Current triangle of intersection
- current_triangleint64
In case a collision has been resolved before, this is the current triangle id the ray origin is located on.
- Returns
- tuple(boolean, float64, int64)
intersection_in_cell, t_min, triangle_of_intersection
See also
ray_triangle_intersection
Notes
t_min and triangle_of_intersection are only updated if a new detected intersection is closer to the ray origin than the t_min that has been passed to the function. The algorithm has to include these kind of tests, because a triangle may intersect with the current cell and is therefore tested for collision but teh collision itself may take place far away from the current cell because the triangle extends the cell. Also, if a collision has been resolved before, the current orign of the ray will be located in the plane of the triangle the ray collided with. Therefore, this triangle (current_triangle) has to be excluded from the collision test, since a collision test will return True. The algorithm is also optimized such that triangles are not tested multiple times. This could in general be the case since triangles may extend severel cells. Therefore, each triangle keeps a flag/time stamp. The time stamp is increased every time a new ray is cast. For more information also see teh original work by Amanatides and Woo [5].
- pyrid.geometry.intersections_util.ray_triangle_intersection(pos, dX, p0, p1, p2, poi=None)[source]
Tests if a ray intersects with a triangle using the Möller–Trumbore intersection algorithm [7]. For reference see also http://en.wikipedia.org/wiki/M%C3%B6ller%E2%80%93Trumbore_intersection_algorithm.
- Parameters
- posfloat64[3]
Position vector.
- dXfloat64[3]
Direction vector.
- p0float64[3]
Vertex 1
- p1float64[3]
Vertex 2
- p2float64[3]
Vertex 3
- poifloat64[3]
Empty point of intersection vector
- Returns
- tuple(boolean, float64)
True if there is an intersection, distance to triangle plane.
- Raises
- NotImplementedError (just an example)
Brief explanation of why/when this exception is raised
- pyrid.geometry.intersections_util.triangle_cell_intersection_test(p0, p1, p2, cell_center, cell_extent)[source]
Tests if a triangle intersects with a cell. Based on [6], [8] (See “Real-Time Collision Detection”, Chapter 5.2.9 “Testing AAB Against Triangle”, p.169 ff). The algorithm is used to create the cell list for the mesh compartment triangles.
- Parameters
- p0float64[3]
Vertex 1
- p1float64[3]
Vertex 2
- p2float64[3]
Vertex 3
- cell_centerfloat64[3]
Center of the cell
- cell_extentfloat64[3]
Extent of cell
- Returns
- boolean
True if triangle intersects with cell.