Skip to main content
Computes and returns the angle between two vectors represented by the provided points or linestrings. There are three variants possible for ST_Angle: Computes the angle formed by vectors represented by point1 - point2 and point3 - point4 Computes the angle formed by vectors represented by point2 - point1 and point2 - point3 Computes the angle formed by vectors S1 - E1 and S2 - E2, where S and E denote start and end points respectively
If any other geometry type is provided, ST_Angle throws an IllegalArgumentException. Additionally, if any of the provided geometry is empty, ST_Angle throws an IllegalArgumentException.
If a 3D geometry is provided, ST_Angle computes the angle ignoring the z ordinate, equivalent to calling ST_Angle for corresponding 2D geometries.
ST_Angle returns the angle in radian between 0 and 2\Pi. To convert the angle to degrees, use ST_Degrees.
ST_Angle

Signatures

ST_Angle(p1, p2, p3, p4) | ST_Angle(p1, p2, p3) | ST_Angle(line1, line2)

Parameters

p1
Geometry
required
The first point (or first LineString in the two-LineString variant).
p2
Geometry
required
The second point (or second LineString in the two-LineString variant).
p3
Geometry
The third point (used in the 3-point and 4-point variants).
p4
Geometry
The fourth point (used in the 4-point variant only).

Return type

A numeric value.

Examples

SELECT ST_Angle(ST_GeomFromWKT('POINT(0 0)'), ST_GeomFromWKT('POINT (1 1)'), ST_GeomFromWKT('POINT(1 0)'), ST_GeomFromWKT('POINT(6 2)'))
0.4048917862850834
SELECT ST_Angle(ST_GeomFromWKT('POINT (1 1)'), ST_GeomFromWKT('POINT (0 0)'), ST_GeomFromWKT('POINT(3 2)'))
0.19739555984988044
SELECT ST_Angle(ST_GeomFromWKT('LINESTRING (0 0, 1 1)'), ST_GeomFromWKT('LINESTRING (0 0, 3 2)'))
0.19739555984988044