This topic describes the ST_3DShortestLine function. This function returns the shortest line that can be formed by the points of two geometry objects in the 3D space.

Syntax

geometry  ST_3DShortestLine(geometry  g1 , geometry  g2);

Parameters

Parameter Description
g1 The first geometry object that you want to specify.
g2 The second geometry object that you want to specify.

Description

  • If this function finds more than one shortest line between the geometry objects you specify, this function returns only the first shortest line that is found.
  • If the geometry objects that you specify intersect at only one point, this function returns a line whose start point and end point are both the intersection point.
  • If the geometry objects that you specify intersect at more than one point, this function returns a line whose start point and end point are both one of the intersection points.
  • The line that is returned by this function always starts from the first geometry object that you specify and points to the second geometry object that you specify.
  • When you specify the same first and second geometry objects for this function and the ST_3DMaxDistance function, these functions always return the same result.
  • This function supports 3D objects and does not delete z coordinates.
  • This function supports polyhedral surfaces.

Examples

The following example shows the difference between the ST_3DLongestLine function and the ST_3DShortestLine function.
SELECT ST_AsText(ST_3DLongestLine(g1,g2)) as lonest,
             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;
          lonest          |              shortest
--------------------------+------------------------------------
 LINESTRING Z (0 0 0,1 1 .| LINESTRING Z (0 0 0,0.333333333333.
.0)                       |.333 0.333333333333333 0.6666666666.
                          |.66667)
(1 row)