计算直线与平面的交点

PsrFunctionResult ComputePlaneLineIntersectPoint( const PsrPoint &pointOfPlane,
                                                                 const PsrVector3D &normalOfPlane,
                                                                 const PsrPoint &pointOfLine,
                                                                 const PsrVector3D &directionOfLine,
                                                                 PsrPoint &intersectPoint)
{
    PsrLOG_FUNC_TRACE();
    /*
    case1:   centerline need to be extend.
    Plane is decided by the lumen's endpoint and tangent of centerline's endpoint.
    Line is decided by the centerline's endpoint and tangent of centerline's endpoint.

    case2:    lumen or wall need to be extend.
    Plane is decided by the sliceInfo's normal and center.
    Line is decided by the lumen or wall's endpoint and tangent of centerline's endpoint.

    input: 
    pointOfPlane:    the point in the plane. (n1,n2,n3)
    normalOfPlane: the normal vector of the plane. (vp1, vp2, vp3)
    pointOfLine:        the point of the line.  (m1, m2, m3)
    directionOfLine: the direction vector of the plane. (v1, v2, v3).
    output:
    intersectPoint:     the intersectPoint. 
    equation of line:
    x = m1+v1*t;
    y = m2+v2*t;
    z = m3+v3*t;
    equation of plane:
    vp1*(x-n1)+vp2*(y-n2)+vp3*(z-n3)=0;
    so: t = ((n1-m1)*vp1 + (n2-m2)*vp2 + (n3-m3)*vp3)/(vp1*v1+vp2*v2+vp3*v3).
    if:  vp1*v1+vp2*v2+vp3*v3 ==0, no intersecPoint.
    intersecPoint:
    intersecPoint.x = m1+v1*t;
    intersecPoint.y = m2+v2*t;
    intersecPoint.z = m3+v3*t;
    */

    PsrVector3D pointOfPlaneSource(pointOfPlane);
    PsrVector3D pointOfLineSource(pointOfLine);
    PsrVector3D intersectPointSource;

    //factor = vp1*v1+vp2*v2+vp3*v3. if factor==0, there is no crosspoint.
    double factor =  normalOfPlane.Dot(directionOfLine);
    if (factor == 0)
    {
        return PsrFunctionResult(SUCCESS_NO_CROSSPOINT);
    }
    else
    {
        double factorOfLine;   // factorOfLine is the factor "t" of equation line.
        // t = (pointOfPlane-pointOfLine).(normalOfPlane)/factor.
        factorOfLine = pointOfPlaneSource.Substract(pointOfLineSource).Dot(normalOfPlane)/factor;
        // intersecPoint = pointOfLine + (directionOfLine * factorOfLine).
        intersectPointSource = pointOfLineSource.Add(directionOfLine.Scalar(factorOfLine));
        intersectPoint.SetPoint(intersectPointSource.X(),intersectPointSource.Y(),intersectPointSource.Z());
        return PsrFunctionResult::ReturnOK();
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

COSummer

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值