有这么一段代码:
from sympy import Point3D, Plane
p1 = Plane(Point3D(0, 0, 1),
Point3D(0, 1, 0),
Point3D(1, 0, 0))
p2 = p1.equation()
print(p2)
程序输出结果:
-10*x - 10*y - z + 10
此处 a = -10,b=-10,c = -1 且 d = 10。
有没有办法单独输出系数?
由于我没有找到这样的方法,所以我编写了一个解析器来执行此操作,但是由于程序不会以相同的格式生成结果,因此解析器需要大量的细化甚至返工。
我不知道有哪个函数可以直接给出所需形式的系数。在内部,平面由一个点和一个法向量表示。
p1.args
将它们作为元组返回。您的 a
、b
、c
属于正常值。法线与平面上的点之间的点积的负数给出 d
。当然,同一个方程可以乘以任意非零值。
from sympy import Point3D, Plane
p1 = Plane(Point3D(0, 0, 1),
Point3D(0, 1, 0),
Point3D(1, 0, 0))
point, normal = p1.args
p2 = p1.equation()
print(f'{p2 = }')
a, b, c = normal
d = - Point3D(normal).dot(point)
print(f'{a = }, {b = }, {c = }, {d = }')
输出
p2 = -x - y - z + 1
a = -1, b = -1, c = -1, d = 1