
投影点设为M,则有向量QM,ABP的法向 和QM是平行的。
平面的方程为 Ax+By+Cz+D=0;
            
            
              cpp
              
              
            
          
              //* \author  PangYeYi
  //   *  \return Q2 在 P1 P2 Q1 构成的平面的上的投影点
  //   ******************/
    Point3d VEC3::GetProPointOn_Face(const Point3d& P1, const Point3d& P2, const Point3d& Q1, const Point3d& Q2)
    {
        UGAPI::StrPoint P(P1);
        UGAPI::StrPoint Q(P2);
        UGAPI::StrPoint A(Q1);
        UGAPI::StrPoint B(Q2);
        UGAPI::StrPoint PQ = Q - P;
        UGAPI::StrPoint PA = A - P;
        UGAPI::StrPoint normal = PQ.cross(PA);// 法向 叉乘 
      
   
        double D = 0;
        if (normal.point[0] == 0 && normal.point[1] == 0 && normal.point[2] == 0)//平行
        {
            return Point3d(0, 0, 0);
        }
        else
        {    //平面方程  Ax+By+Cz+D=0;  A  B  C 为法向 
            D = (normal.point[0] * P1.X + normal.point[1] * P1.Y + normal.point[2] * P1.Z) * (-1);
        }
     
        double t = normal.point[0] * Q2.X + normal.point[1] * Q2.Y + normal.point[2] * Q2.Z + D;
        //平面法向量 normal 的模长的平方
        double T = normal.point[0] * normal.point[0] + normal.point[1] * normal.point[1] + normal.point[2] * normal.point[2];
      
        UGAPI::StrPoint  res = B + normal * ((-t) / T);// 比例
        return res.ToPoint3d();
    }