# psychopy.tools.mathtools.intersectRayTriangle¶

psychopy.tools.mathtools.intersectRayTriangle(rayOrig, rayDir, tri, dtype=None)[source]

Get the intersection of a ray and triangle(s).

This function can be used to achieve ‘pixel-perfect’ ray picking/casting on meshes defined with triangles. However, high-poly meshes may lead to performance issues.

Parameters
• rayOrig (array_like) – Origin of the ray in space [x, y, z].

• rayDir (array_like) – Direction vector of the ray [x, y, z], should be normalized.

• tri (array_like) – Triangle vertices as 2D (3x3) array [p0, p1, p2] where each vertex is a length 3 array [vx, xy, vz]. The input array can be 3D (Nx3x3) to specify multiple triangles.

• dtype (dtype or str, optional) – Data type for computations can either be ‘float32’ or ‘float64’. If out is specified, the data type of out is used and this argument is ignored. If out is not provided, ‘float64’ is used by default.

Returns

Coordinate in world space of the intersection, distance in scene units from rayOrig, and the barycentric coordinates on the triangle [x, y]. Returns None if there is no intersection.

Return type

tuple