psychopy.tools.mathtools.intersectRayPlane

psychopy.tools.mathtools.intersectRayPlane(rayOrig, rayDir, planeOrig, planeNormal, dtype=None)[source]

Get the point which a ray intersects a plane.

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

  • rayDir (array_like) – Direction vector of the line [x, y, z].

  • planeOrig (array_like) – Origin of the plane to test [x, y, z].

  • planeNormal (array_like) – Normal vector of the plane [x, y, z].

  • 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

Position (ndarray) in space which the line intersects the plane and the distance the intersect occurs from the origin (float). None is returned if the line does not intersect the plane at a single point or at all.

Return type

tuple or None

Examples

Find the point in the scene a ray intersects the plane:

# plane information
planeOrigin = [0, 0, 0]
planeNormal = [0, 0, 1]
planeUpAxis = perp([0, 1, 0], planeNormal)

# ray
rayDir = [0, 0, -1]
rayOrigin = [0, 0, 5]

# get the intersect and distance in 3D world space
pnt, dist = intersectRayPlane(rayOrigin, rayDir, planeOrigin, planeNormal)

Back to top