已知四个点ABPQ,求Q点在ABP平面的投影点。如果已经共面了,投影点和Q重合

投影点设为M,则有向量QM,ABP的法向 和QM是平行的。

平面的方程为 Ax+By+Cz+D=0;

    //* \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();
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值