vtk实战(二)——点到直线的距离

vtk中计算点到直线的距离有两个重载函数。

//x[3]表示点的x,y,z坐标,  p1[3],p2[3] 分别为直线上的两个点
//函数都返回的为距离的平方
/*注意:重载1中计算点到直线的距离;重载2计算点到线段的最近距离,距离最近的点必定在线段上,p1[3],p2[3]分别为线段的端点*/

//重载1
static double vtkLine::DistanceToLine   (   double  x[3],
double  p1[3],
double  p2[3]    
)   
//重载2
static double vtkLine::DistanceToLine   (   double  x[3],
double  p1[3],
double  p2[3],
double &    t,
double  closestPoint[3]  
)   

本节实例代码:

#include <vtkSmartPointer.h>
#include <vtkLine.h>
#include <vtkPoints.h>

int main()
{
    double lineP0[3] = { 0.0, 0.0, 0.0 };
    double lineP1[3] = { 2.0, 0.0, 0.0 };

    double p0[3] = { 3.0, 1.0, 0 };
    double p1[3] = { 1.0, 2.0, 0 };

    {
        double dist0 = vtkLine::DistanceToLine(p0, lineP0, lineP1);
        std::cout << "Dist0: " << dist0 << std::endl;

        double dist1 = vtkLine::DistanceToLine(p1, lineP0, lineP1);
        std::cout << "Dist1: " << dist1 << std::endl;
    }

    {
        double t;
        double closest[3];
        double dist0 = vtkLine::DistanceToLine(p0, lineP0, lineP1, t, closest);
        std::cout << "Dist0: " << dist0 << " closest point: " << closest[0] << " " << closest[1] << " " << closest[2] << std::endl;

        double dist1 = vtkLine::DistanceToLine(p1, lineP0, lineP1, t, closest);
        std::cout << "Dist1: " << dist1 << " closest point: " << closest[0] << " " << closest[1] << " " << closest[2] << std::endl;
    }
    return 0;
}

vtk中计算点到直线的距离

本节代码:http://pan.baidu.com/s/1slIJvUd

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值