vtk基础编程(1)计算点到直线的距离

原文地址: http://blog.csdn.net/chinamming/article/details/16841503

1. 首先涉及到的类为vtkline, 其类继承关系为

2. 点到直线距离常用成员函数为

1) 计算点到直线的距离,并求出最近点
static double vtkLine::DistanceToLine ( double x[3],
double p1[3],
double p2[3],
double & t,
double closestPoint[3]
)

2) 计算点到直线的距离
static double vtkLine::DistanceToLine ( double x[3],
double p1[3],
double p2[3]
)

[示范程序]

int main(int, char *[])
{
    double lineP0[3] = {0.0, 0.0, 0.0};
    double lineP1[3] = {2.0, 0.0, 0.0};
    
    double p0[3] = {1.0, 0, 0};
    double p1[3] = {1.0, 2.0, 0};
    
    /*
    vtkSmartPointer<vtkLine> line =  vtkSmartPointer<vtkLine>::New();
    line->GetPoints()->SetPoint(0, lineP0);
    line->GetPoints()->SetPoint(0, lineP1);
    */
    
    {
        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 EXIT_SUCCESS;
}

原文地址: http://blog.csdn.net/chinamming/article/details/16841503


程序源码下载地址

http://download.csdn.net/detail/chinamming/6580341

版权声明:本文为博主原创文章,未经博主允许不得转载。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值