ST_Angle

Syntax

DOUBLE ST_Angle(GEOPOINT point1, GEOPOINT point2, GEOPOINT point3)

description

Enter three point, which represent two intersecting lines. Returns the angle between these lines. Point 2 and point 1 represent the first line and point 2 and point 3 represent the second line. The angle between these lines is in radians, in the range [0, 2pi). The angle is measured clockwise from the first line to the second line.

ST_ANGLE has the following edge cases:

  • If points 2 and 3 are the same, returns NULL.
  • If points 2 and 1 are the same, returns NULL.
  • If points 2 and 3 are exactly antipodal, returns NULL.
  • If points 2 and 1 are exactly antipodal, returns NULL.
  • If any of the input geographies are not single points or are the empty geography, then throws an error.

example

1. mysql> SELECT ST_Angle(ST_Point(1, 0),ST_Point(0, 0),ST_Point(0, 1));
2. +----------------------------------------------------------------------+
3. | st_angle(st_point(1.0, 0.0), st_point(0.0, 0.0), st_point(0.0, 1.0)) |
4. +----------------------------------------------------------------------+
5. |                                                     4.71238898038469 |
6. +----------------------------------------------------------------------+
7. 1 row in set (0.04 sec)

9. mysql> SELECT ST_Angle(ST_Point(0, 0),ST_Point(1, 0),ST_Point(0, 1));
10. +----------------------------------------------------------------------+
11. | st_angle(st_point(0.0, 0.0), st_point(1.0, 0.0), st_point(0.0, 1.0)) |
12. +----------------------------------------------------------------------+
13. |                                                  0.78547432161873854 |
14. +----------------------------------------------------------------------+
15. 1 row in set (0.02 sec)

17. mysql> SELECT ST_Angle(ST_Point(1, 0),ST_Point(0, 0),ST_Point(1, 0));
18. +----------------------------------------------------------------------+
19. | st_angle(st_point(1.0, 0.0), st_point(0.0, 0.0), st_point(1.0, 0.0)) |
20. +----------------------------------------------------------------------+
21. |                                                                    0 |
22. +----------------------------------------------------------------------+
23. 1 row in set (0.02 sec)

25. mysql> SELECT ST_Angle(ST_Point(1, 0),ST_Point(0, 0),ST_Point(0, 0));
26. +----------------------------------------------------------------------+
27. | st_angle(st_point(1.0, 0.0), st_point(0.0, 0.0), st_point(0.0, 0.0)) |
28. +----------------------------------------------------------------------+
29. |                                                                 NULL |
30. +----------------------------------------------------------------------+
31. 1 row in set (0.03 sec)

33. mysql> SELECT ST_Angle(ST_Point(0, 0),ST_Point(-30, 0),ST_Point(150, 0));
34. +--------------------------------------------------------------------------+
35. | st_angle(st_point(0.0, 0.0), st_point(-30.0, 0.0), st_point(150.0, 0.0)) |
36. +--------------------------------------------------------------------------+
37. |                                                                     NULL |
38. +--------------------------------------------------------------------------+
39. 1 row in set (0.02 sec)

keywords

ST_ANGLE,ST,ANGLE