来自点和方向矢量的 3D 矢量线

3D vector line from a point and a directional vector

我正在尝试使用直线 P(0) 上的一个点和方向向量 V

获取 3D 直线

我发现 SymPy 有库可以使用两点而不是向量和点来获取线。有什么方法可以将行作为对象获取吗?

我的最终动机是找到那条线和平面的交点。 到目前为止,这是我的代码

import numpy as np

from sympy import Plane, Line3D, Point3D #it's not needed here

#plane Points
a1 = Point3D (-5,15,-5)
a2 = Point3D (5,15,-5)
a3 = Point3D (5,15,5)
#line Points
p0 = Point3D (0,3,1) #point in line
v0 = [0, 1 ,1] #line direction as vector

#create plane and line
plane = Plane(a1,a2,a3)

line = # Need to find the line


print(f"plane equation: {plane.equation()}")
print(f"line equation: {line.equation()}")

#find intersection:

intr = plane.intersection(line)

intersection =np.array(intr[0],dtype=float)
print(f"intersection: {intersection}")

仔细浏览图书馆后,我找到了问题的答案。

当你有线(方向比)v0 和矢量 p0 上的点时,可以使用以下方法获取 3D 线矢量。

line = Line3D(p0,direction_ratio=v0) 因此完整的代码将是。


from sympy import Plane, Line3D, Point3D 

#plane Points
a1 = Point3D (-5,15,-5)
a2 = Point3D (5,15,-5)
a3 = Point3D (5,15,5)
#line Points
p0 = Point3D (0,3,1) #point in line
v0 = [0, 1 ,1] #line direction as vector

#create plane and line
plane = Plane(a1,a2,a3)

line = Line3D(p0,direction_ratio=v0)


print(f"plane equation: {plane.equation()}")
print(f"line equation: {line.equation()}")

#find intersection:

intr = plane.intersection(line)

intersection =np.array(intr[0],dtype=float)
print(f"intersection: {intersection}")```