前几天写了一篇关于旋转门的数据压缩算法在postgresql中的实现,里面用到了postgis里面的st_azimuth函数用来计算夹角,其实在postgresql 中,我们还可以使用三角函数,以及三边来求夹角。
<a href="https://yq.aliyun.com/articles/59101">https://yq.aliyun.com/articles/59101</a>

文中用到的计算夹角的方法如下
cosa=(b²+c²-a²)/(2bc)
定点为a、b、c; 对的边分别为a、b、c;
<a href="https://www.postgresql.org/docs/9.6/static/functions-math.html">https://www.postgresql.org/docs/9.6/static/functions-math.html</a>
function (radians)
function (degrees)
description
acos(x)
acosd(x)
inverse cosine
asin(x)
asind(x)
inverse sine
atan(x)
atand(x)
inverse tangent
atan2(y, x)
atan2d(y, x)
inverse tangent of y/x
cos(x)
cosd(x)
cosine
cot(x)
cotd(x)
cotangent
sin(x)
sind(x)
sine
tan(x)
tand(x)
tangent
已知三个点a(3,2),b(1,2.5),c(1,1)。 求夹角b, c。
套用余弦公式
首先求三条边长
运算如下
求夹角 1 度数
求夹角 2 度数
比对使用postgis计算的结果一致
三角函数属于浮点运算中的函数
src/backend/utils/adt/float.c
祝大家玩得开心,欢迎随时来 阿里云促膝长谈业务需求 ,恭候光临。
阿里云的小伙伴们加油,努力 做好内核与服务,打造最贴地气的云数据库 。