All Products
Search
Document Center

PolarDB:ST_3DShortestLine

Last Updated:Mar 28, 2026

ST_3DShortestLine returns the shortest line between two geometry objects in 3D space.

Syntax

geometry ST_3DShortestLine(geometry g1, geometry g2);

Parameters

ParameterDescription
g1The first geometry object.
g2The second geometry object.

Description

  • If more than one shortest line exists between the two geometry objects, the function returns only the first one found.

  • If the geometry objects intersect at exactly one point, the returned line has both its start point and end point at that intersection point.

  • If the geometry objects intersect at more than one point, the returned line has both its start point and end point at one of those intersection points.

  • The returned line always starts from g1 and points toward g2.

  • When you pass the same g1 and g2 to ST_3DShortestLine and ST_3DMaxDistance, both functions return the same result.

  • Supports 3D objects and preserves Z coordinates.

  • Supports polyhedral surfaces.

Examples

The following example compares the output of ST_3DLongestLine and ST_3DShortestLine for a point and a line string.

SELECT ST_AsText(ST_3DLongestLine(g1, g2))  AS longest,
       ST_AsText(ST_3DShortestLine(g1, g2)) AS shortest
FROM (
    SELECT 'POINT(0 0 0)'::geometry            AS g1,
           'LINESTRING(0 0 1,1 1 0)'::geometry AS g2
) AS test;

Output:

longest                    | shortest
---------------------------+--------------------------------------------------------------------
LINESTRING Z (0 0 0,1 1 0) | LINESTRING Z (0 0 0,0.333333333333333 0.333333333333333 0.666666666666667)
(1 row)

Related functions

  • ST_3DLongestLine — returns the longest line between two geometry objects in 3D space

  • ST_3DMaxDistance — calculates the farthest distance between two geometry objects in 3D space