python点到向量的距离,夹角
2021/10/4 12:40:44
本文主要是介绍python点到向量的距离,夹角,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
import numpy as np def angle(v1, v2): dx1 = v1[2] - v1[0] dy1 = -(v1[3] - v1[1]) dx2 = v2[2] - v2[0] dy2 = -(v2[3] - v2[1]) angle1 = math.atan2(dy1, dx1) angle1 = -int(angle1 * 180 / math.pi) if angle1 < 0: angle1 = 360 + angle1 # print(angle1) angle2 = math.atan2(dy2, dx2) angle2 = - int(angle2 * 180 / math.pi) if angle2 < 0: angle2 = 360 + angle2 print(angle1, angle2) included_angle = angle1 - angle2 if abs(included_angle) > 180: included_angle = included_angle / abs(included_angle) * (360 - abs(included_angle)) else: included_angle *= -1 return included_angle if __name__ == '__main__': import math AB = [2, 5, 4, 1] CD = [2, 5, 5, 3] ang1 = angle(AB, CD) print("AB和CD的夹角") print(ang1) ang1 = angle(CD, AB) print("CD和AB的夹角") print(ang1) dis_long=np.sqrt((CD[3]-CD[1])**2+(CD[2]-CD[0])**2) print(dis_long) dis2= (ang1 / 180 * math.pi)*dis_long print(abs(dis2))
这篇关于python点到向量的距离,夹角的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-14获取参数学习:Python编程入门教程
- 2024-11-14Python编程基础入门
- 2024-11-14Python编程入门指南
- 2024-11-13Python基础教程
- 2024-11-12Python编程基础指南
- 2024-11-12Python基础编程教程
- 2024-11-08Python编程基础与实践示例
- 2024-11-07Python编程基础指南
- 2024-11-06Python编程基础入门指南
- 2024-11-06怎么使用python 计算两个GPS的距离功能-icode9专业技术文章分享