V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
niceTeen84
V2EX  ›  数学

请教两平面相交的问题

  •  
  •   niceTeen84 · 293 天前 · 1045 次点击
    这是一个创建于 293 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    已知两个平面的方程为:

    平面 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)
    

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

    2 条回复    2023-07-11 17:27:02 +08:00
    misdake
        1
    misdake  
       293 天前 via Android   ❤️ 1
    看起来好像没啥问题。但他需要 abc 是单位向量,所以输入的时候要整理平面方程。
    necomancer
        2
    necomancer  
       291 天前   ❤️ 1
    这个要看直线方程的写法,比如直线可以定义为(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 )。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1814 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 16:20 · PVG 00:20 · LAX 09:20 · JFK 12:20
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.