原文地址: 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
版权声明:本文为博主原创文章,未经博主允许不得转载。