请教两平面相交的问题

305 天前
 niceTeen84

工作中遇到两平面求相交直线方程的问题:

已知两个平面的方程为:

平面 1: 15274.32X + 16334.64Y + 3910347.7Z -1217342147660.14 = 0

平面 2: -14272.59X + -32556.69Y + 3899632.2Z + 1993749987653.63 = 0

如何何求点向式的直线方程?

我问了 chatGPT 代码如下:

def line_intersect(p1, p2):
    """
    Finds the line of intersection between two planes given their equations in the form ax + by + cz = d.
    Returns the direction vector of the line and a point on the line.
    """
    a1, b1, c1, d1 = p1
    a2, b2, c2, d2 = p2
    # Compute the direction vector of the line of intersection
    direction = (b1 * c2 - b2 * c1, a2 * c1 - a1 * c2, a1 * b2 - a2 * b1)
    # Find a point on the line of intersection
    x = (b1 * d2 - b2 * d1) / (a1 * b2 - a2 * b1)
    y = (a2 * d1 - a1 * d2) / (a1 * b2 - a2 * b1)
    z = 0
    if c1 != 0:
        z = d1 / c1
    elif c2 != 0:
        z = d2 / c2
    return direction, (x, y, z)

我数学基础较差,都不知道给的答案对不对,恳请各位大佬给解答一下,谢谢。

1067 次点击
所在节点    数学
2 条回复
misdake
305 天前
看起来好像没啥问题。但他需要 abc 是单位向量,所以输入的时候要整理平面方程。
necomancer
303 天前
这个要看直线方程的写法,比如直线可以定义为(x-x0)/a = (y-y0)/b = (z-z0)/c ,或者参数方程 r = r0 + t * d 的形式,其中 r0=(x0, y0, z0) 是固定点,也是两个平面的交点,d 是直线的方向向量,t 为任意实数。程序看着好像没问题,利用了第二种表达方法:因为 d 和两个平面的法向量都垂直,所以 d = n1 x n2 ,也就是 direction = (b1* c2,...),x0, y0, z0 是同时满足两个平面方程的的点,有无穷多个,只要解出来任意一个就行,也就是从欠定方程 a1 x + b1 y + c1 z + d1 = 0 和 a2 x + b2 y + c2 z + d2 = 0 里猜一个解就行,例如令 z = 0 ,解 x0, y0 。但是这里有一些特殊情况,就是直线有可能和 xy 面平行,也就是有可能不过 z=0 的点,这种情况也就是 c1 = c2 = 0 的情况,求出 z ,得到一组特解。也就是函数返回的 direction 和 ( x,y,z )。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/955277

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX