ST_Angle
Prev | 8.12. Measurement Functions | Next

## Name

ST_Angle — Returns the angle between two vectors defined by 3 or 4 points, or 2 lines.

## Synopsis

`float ST_Angle(`geometry point1, geometry point2, geometry point3, geometry point4`)`;

`float ST_Angle(`geometry line1, geometry line2`)`;

## Description

Computes the clockwise angle between two vectors.

Variant 1: computes the angle enclosed by the points P1-P2-P3. If a 4th point provided computes the angle points P1-P2 and P3-P4

Variant 2: computes the angle between two vectors S1-E1 and S2-E2, defined by the start and end points of the input lines

The result is a positive angle between 0 and 2π radians. The radian result can be converted to degrees using the PostgreSQL function `degrees()`.

Note that `ST_Angle(P1,P2,P3) = ST_Angle(P2,P1,P2,P3)`.

Availability: 2.5.0

## Examples

Angle between three points

    SELECT degrees( ST_Angle('POINT(0 0)', 'POINT(10 10)', 'POINT(20 0)') );

     degrees
    ---------
         270

Angle between vectors defined by four points

    SELECT degrees( ST_Angle('POINT (10 10)', 'POINT (0 0)', 'POINT(90 90)', 'POINT (100 80)') );

          degrees
    -------------------
     269.9999999999999

Angle between vectors defined by the start and end points of lines

    SELECT degrees( ST_Angle('LINESTRING(0 0, 0.3 0.7, 1 1)', 'LINESTRING(0 0, 0.2 0.5, 1 0)') );

          degrees
    --------------
               45

## See Also

ST_Azimuth

Prev | Up | Next
ST_Azimuth | Home | ST_ClosestPoint