点之间的角度? [英] Angle between points?

查看:78
本文介绍了点之间的角度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个三角形(A,B,C),并试图找到这三个点之间的夹角.

I have a triangle (A, B, C) and am trying to find the angle between each pair of the three points.

问题是我可以在网上找到的算法是用于确定向量之间的角度的.使用这些向量,我可以计算出从(0,0)到我拥有的点之间的向量之间的角度,而这不会给我三角形内部的角度.

The problem is that the algorithms I can find online are for determining the angle between vectors. Using the vectors I would compute the angle between the vector that goes from (0, 0) to the point I have, and that doesn't give me the angles inside the triangle.

好的,这是Wikipedia页面上的方法之后以及减去值之后的Python中的一些代码:

OK, here's some code in Python after the method on the Wikipedia page and after subtracting the values:

import numpy as np
points = np.array([[343.8998, 168.1526], [351.2377, 173.7503], [353.531, 182.72]])

A = points[2] - points[0]
B = points[1] - points[0]
C = points[2] - points[1]

for e1, e2 in ((A, B), (A, C), (B, C)):
    num = np.dot(e1, e2)
    denom = np.linalg.norm(e1) * np.linalg.norm(e2)
    print np.arccos(num/denom) * 180

那给了我60.2912487814、60.0951900475和120.386438829,那我做错了什么?

That gives me 60.2912487814, 60.0951900475 and 120.386438829, so what am I doing wrong?

推荐答案

这里有两个错误.

  • 您错过了系数π从弧度转换为度时(× 180/π)

  • You missed a factor of π when translating from radians to degrees (it's × 180 / π)

由于矢量是有向线段,因此必须小心矢量的符号.

You have to be careful about the signs of vectors, since they are directed line segments.

如果我进行了这些修改,我将得到一个有意义的结果:

If I make these modifications I get a result that makes sense:

import numpy as np
points = np.array([[343.8998, 168.1526], [351.2377, 173.7503], [353.531, 182.72]])

A = points[2] - points[0]
B = points[1] - points[0]
C = points[2] - points[1]

angles = []
for e1, e2 in ((A, B), (A, C), (B, -C)):
    num = np.dot(e1, e2)
    denom = np.linalg.norm(e1) * np.linalg.norm(e2)
    angles.append(np.arccos(num/denom) * 180 / np.pi)
print angles
print sum(angles)

打印出来的

[19.191300537488704, 19.12889310421054, 141.67980635830079]
180.0

我可能会让事情变得更加对称,并使用A,B,C循环且总和为零的向量:

I'd probably make things more symmetrical and use A, B, C vectors that are cyclic and sum to zero:

import numpy as np
points = np.array([[343.8998, 168.1526], [351.2377, 173.7503], [353.531, 182.72]])

A = points[1] - points[0]
B = points[2] - points[1]
C = points[0] - points[2]

angles = []
for e1, e2 in ((A, -B), (B, -C), (C, -A)):
    num = np.dot(e1, e2)
    denom = np.linalg.norm(e1) * np.linalg.norm(e2)
    angles.append(np.arccos(num/denom) * 180 / np.pi)
print angles
print sum(angles)

打印出来的

[141.67980635830079, 19.12889310421054, 19.191300537488704]
180.0

点积中的负号出现是因为我们试图获取内角.

The minus signs in the dot product come because we're trying to get the inside angles.

很抱歉,我们通过关闭问题将您赶在需要的时候.

I'm sorry we drove you away in your time of need, by closing the question.

这篇关于点之间的角度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆