跳到主要内容

ST_ANGLE

描述

输入三个点,第一条线表示是 point1 点为第一个端点,point2 点为第二个端点相连的直线,第二条线表示对是 point1 为第一个端点,point2 为第二个端点相连的直线,它们表示两条相交的线。返回第一条直线顺时针到第二条直线的夹角,每个端点坐标的 x 为纬度,都要求范围在[-180,180] ,每个坐标的 y 轴要求范围在[-90,90]。

语法

ST_ANGLE( <point1>, <point2>, <point3>)

参数

参数说明
<point1>第一条直线的第一个端点 ,类型为 GeoPoint
<point2>第一条直线的第二个端点且是第二条直线的第一个端点, 类型为 GeoPoint
<point3>第二条直线的第二个端点, 类型为 GeoPint

返回值

这些线之间的夹角以弧度表示,范围为 [0, 2pi),为一个double类型浮点数。夹角按顺时针方向从第一条线开始测量,直至第二条线。

ST_ANGLE 存在以下边缘情况:

  • 如果点 2 和点 3 相同,则返回 NULL。
  • 如果点 2 和点 1 相同,则返回 NULL。
  • 如果点 2 和点 3 是完全对映点,则返回 NULL。
  • 如果点 2 和点 1 是完全对映点,则返回 NULL。
  • 如果某个点超过 xy的范围,则返回NULL
  • 任意坐标为NULL,返回NULL

举例

SELECT ST_Angle(ST_Point(1, 0),ST_Point(0, 0),ST_Point(0, 1));

第一条线到第二条线顺时针弧度为4.7

+----------------------------------------------------------------------+
| st_angle(st_point(1.0, 0.0), st_point(0.0, 0.0), st_point(0.0, 1.0)) |
+----------------------------------------------------------------------+
| 4.71238898038469 |
+----------------------------------------------------------------------+
SELECT ST_Angle(ST_Point(0, 0),ST_Point(1, 0),ST_Point(0, 1));

第一条线到第二条线顺时针弧度为0.78

+----------------------------------------------------------------------+
| st_angle(st_point(0.0, 0.0), st_point(1.0, 0.0), st_point(0.0, 1.0)) |
+----------------------------------------------------------------------+
| 0.78547432161873854 |
+----------------------------------------------------------------------+
SELECT ST_Angle(ST_Point(1, 0),ST_Point(0, 0),ST_Point(1, 0));

两线重叠,顺时针角度为0,返回0

+----------------------------------------------------------------------+
| st_angle(st_point(1.0, 0.0), st_point(0.0, 0.0), st_point(1.0, 0.0)) |
+----------------------------------------------------------------------+
| 0 |
+----------------------------------------------------------------------+

点2和点3是同一点,返回NULL

SELECT ST_Angle(ST_Point(1, 0),ST_Point(0, 0),ST_Point(0, 0));
+----------------------------------------------------------------------+
| st_angle(st_point(1.0, 0.0), st_point(0.0, 0.0), st_point(0.0, 0.0)) |
+----------------------------------------------------------------------+
| NULL |
+----------------------------------------------------------------------+

两点对映,返回NULL

SELECT ST_Angle(ST_Point(0, 0),ST_Point(-30, 0),ST_Point(150, 0));
+--------------------------------------------------------------------------+
| st_angle(st_point(0.0, 0.0), st_point(-30.0, 0.0), st_point(150.0, 0.0)) |
+--------------------------------------------------------------------------+
| NULL |
+--------------------------------------------------------------------------+

任意一点是NULL,则返回NULL

mysql> SELECT ST_Angle(NULL,ST_Point(-30, 0),ST_Point(-150, 0)) ;
+---------------------------------------------------+
| ST_Angle(NULL,ST_Point(-30, 0),ST_Point(-150, 0)) |
+---------------------------------------------------+
| NULL |
+---------------------------------------------------+

任意坐标超过规定点的范围,返回NULL


mysql> SELECT ST_Angle(ST_Point(0, 0),ST_Point(-30, 0),ST_Point(180, 91));
+-------------------------------------------------------------+
| ST_Angle(ST_Point(0, 0),ST_Point(-30, 0),ST_Point(180, 91)) |
+-------------------------------------------------------------+
| NULL |
+-------------------------------------------------------------+

任一坐标为NULL,返回NULL

mysql> SELECT ST_Angle(NULL,ST_Point(-30, 0),ST_Point(150, 90));
+---------------------------------------------------+
| ST_Angle(NULL,ST_Point(-30, 0),ST_Point(150, 90)) |
+---------------------------------------------------+
| NULL |
+---------------------------------------------------+