All Products
Search
Document Center

PolarDB:ST_RayIntersection

Last Updated:Mar 28, 2026

Calculates the intersections between a set of rays and an sfmesh object in a single call.

Syntax

geometry ST_RayIntersection(sfmesh sfmesh, geometry mpoint, geometry direction);

Parameters

ParameterTypeDescription
sfmeshsfmeshThe sfmesh model object.
mpointMULTIPOINTThe endpoint of the ray.
directionPOINTThe shared direction of all rays. All rays in the batch travel in this direction.

Return value

Returns a MULTIPOINT geometry representing the intersections of sfmesh objects and rays.

If no intersection exists, EMPTY is returned.

Usage notes

  • mpoint specifies the endpoint of the ray and is of the MULTIPOINT type.

  • direction specifies the direction of the ray and is of the POINT type.

  • All rays share a single direction, specified by direction. To calculate intersections for rays in different directions, call ST_RayIntersection separately for each direction.

  • The input sfmesh is typically created by casting a geometry to meshgeom (for example, 'POLYGON(...)'::geometry::meshgeom).

Examples

Rays intersecting a mesh plane

Calculate the intersections of four rays — all traveling in the direction (0, 1, 0) — against a unit-square mesh centered at the origin on the XY plane.

SELECT ST_AsText(
  ST_RayIntersection(
    'POLYGON((-1 -1 0, 1 -1 0, 1 1 0, -1 1 0, -1 -1 0))'::geometry::meshgeom,
    'MULTIPOINT(0 0 0, 0 1 0, 0 -1 0, 0 -2 0)'::geometry,
    'POINT(0 1 0)'::geometry
  )
);

Expected output:

 MULTIPOINT Z ((0 0 0),(0 1 0),(0 -1 0),(0 -1 0))