利用python计算两点构成的方向向量

您所在的位置:网站首页 空间两点向量相乘 利用python计算两点构成的方向向量

利用python计算两点构成的方向向量

2023-09-01 23:19| 来源: 网络整理| 查看: 265

calVectorFrom2Points 功能

利用空间两点坐标计算该直线的方向向量 s ( m , n , p ) s(m,n,p) s(m,n,p)。

原理

如图所示,空间任意两点 P o i n t 1 ( x 1 , y 1 , z 1 ) Point_{1}(x_1,y_1,z_1) Point1​(x1​,y1​,z1​)和 P o i n t 2 ( x 2 , y 2 , z 2 ) Point_{2}(x_2,y_2,z_2) Point2​(x2​,y2​,z2​)。

https://gitee.com/zhaoqiushan/pic/raw/master/422b4a043c61013b3f03b5c4b20539a.png

根据上图可知空间直线的方向向量 s s s可由空间两点做差值获得: s ⃗ = P o i n t 1 − P o i n t 2 = ( x 1 − x 2 , y 1 − y 2 , z 1 − z 2 ) \vec{s}=Point_{1}-Point_{2}=(x_1-x_2,y_1-y_2,z_1-z_2) s =Point1​−Point2​=(x1​−x2​,y1​−y2​,z1​−z2​)

使用 输入

空间任意两点坐标 P o i n t 1 ( x 1 , y 1 , z 1 ) Point_{1}(x_1,y_1,z_1) Point1​(x1​,y1​,z1​)、 P o i n t 2 ( x 2 , y 2 , z 2 ) Point_{2}(x_2,y_2,z_2) Point2​(x2​,y2​,z2​)。

输出

上述两点所在直线的方向向量 s ( m , n , p ) s(m,n,p) s(m,n,p)。

DEMO import geomeas as gm import numpy as np Point_1 = np.array([227.15, 174.45, 0]) Point_2 = np.array([-108.45, 251.72, 0]) print(gm.Vector().calVectorFrom2Points(Point_1, Point_2))

代码链接



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3