• 多维空间下求平面交线的通用方法


    先说明两个表示方法:

    差乘  crossProduct:a.crossProcut(b) = a*b*sin<a, b>

    点乘法 dotProduct : a.dotProduct(b) = a* b * cos<a, b>

    A(x0, y0, z0) 为平面原点, 点p(x, y, z) 为平面上任意一点,N(a, b,c) 为平面法线, 则有

    N.dotProduct(A - p) = 0  => N.dotProduct(p) = N.dotProduct(A)

    则可知, 平面方程: N.dotProduct(p) = d  (d为常数)

    若两平面不平行, 可用法线定义平面方程:

    N1.dotProduct(p) = d1                                                  (1)

    N2.dotProduct(p) = d2                                                  (2)

    则直线方程如下:

    p = c1*N1 + c2 * N2 + t * N1.crossProduct(N2)  (t         (3)

    联立方程(1)(2)(3)可得

    c1 = ( d1 N22 - d2 N1.dotProduct(N2)/ determinant

    c2 = ( d2 N12- d1 N1.dotProduct(N2) / determinant

    determinant = N12N22 - (N1.dotProduct(N2))2

    详细代码如下:

    public static Line GetIntersectionOfTwoPlane(Plane plane1, plane2)
    {
        // 获取平面法相以及 常数 d 
        XYZ N1 = plane1.Normal;
        XYZ N2 = plane2.Normal;
        
        if(N1.crossProduct(N2) == 0) {return null}
        
        double d1 = N1.dotProduct(plane1.origin)
        double d2 = N2.dotProduct(plane2.origin)
        
        double determinant = (N1.dotProduct(N1) * N2.dotProduct(N2)) - (N1,dotProduct(N2) * N1.dotProduct(N2));
        double c1 = (d1 * N2.dotProduct(N2) - d2.N1.dotProduct(N2) / determinant;
        double c2 = (d2 * N1.dotProduct(N1) - d2.N1.dotProduct(N2) / determinant;
        
        // p = c1 * N1 + c2 * N2 + t * N1.crossProduct(N2)
    }
  • 相关阅读:
    线程间协作的两种方式:wait、notify、notifyAll和Condition
    Lock
    线程池ExecutorService的使用
    使用volatile的条件
    解决共享资源竞争
    并发时捕获异常
    Executor执行器
    BufferedReader 和BufferedWriter
    彻底理解Java的Future模式
    贝叶斯网络简介--翻译版
  • 原文地址:https://www.cnblogs.com/yaolin1228/p/7905234.html
Copyright © 2020-2023  润新知