找到两条给定线2D之间的角度 [英] Find the angle between two given lines 2D

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

问题描述

我得到的输入是4分.

p1 =(x1,y1),p2 =(x2,y2),p3 =(x3,y3),p4 =(x4,y4).

p1=(x1, y1), p2=(x2, y2), p3=(x3, y3), p4=(x4, y4).

现在我已经计算出p1p2,p2p3,p3p4和p4p1之间的距离.

Now I have calculated the distances between p1p2, p2p3, p3p4 and p4p1.

如何计算p1p2和p2p3之间的角度?这就是角度p2. (显示在下面的图片链接中);

How do I calculate the angle between p1p2 and p2p3 ? which is the angle p2. (shown in image link below);

我尝试过

 acos((p1p2)^2 + (p2p3)^2 - (p1p3)^2)/(2*p1p2*p2p3))*(180/pi)

但这并不准确,我想对4个角度求和,并检查它们的总和是否为360.因此,我永远不会得到一个无理数.

But this is not accurate, I want to sum 4 angles and check if they sum to 360. And this way I'll never get an irrational number.

请帮忙吗?

推荐答案

要获取两个向量之间的夹角,只需使用它们的内积即可:

To get the angle between two vectors, you simply use their inner product:

v1 = p1-p2;
v2 = p3-p2;

归一化为单位向量并取内积:

Normalize to unit vectors and take inner product:

n1 = v1/norm(v1);
n2 = v2/norm(v2);

cos_p2 = dot(n1,n2);

结果角度为

acos(cos_p2)

这篇关于找到两条给定线2D之间的角度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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