[VTK] VTK calculates the projection point of point A on the tangent plane of point B

VTK calculates the projection point of point A on the tangent plane of point B


To find the tangent plane of a certain point on the model, the tangent vector of the point is not needed, only the normal vector of the point is needed. Use vtkPolyDataNormals to calculate the normal vector of the model, and then use vtkPlane to find the tangent plane of a point. The projection function ProjectPoint is provided in vtkPlane.

Important: ProjectPoint is a static method of vtkPlane, which can be called directly without creating a cut plane object for each vertex .

  • Function introduction:
static void ProjectPoint(
    const double x[3], const double origin[3], const double normal[3], double xproj[3]);
    //x: 被投影的A点 
    //origin: B点坐标
    //normal: B点法向量
    //xproj: A点投影结果
  • Core code:
	//计算法向量
	vtkNew<vtkPolyDataNormals> normalFilter;
	normalFilter->SetInputData(polyData);
	normalFilter->SetComputePointNormals(true);
	normalFilter->Update();
	normals = normalFilter->GetOutput()->GetPointData()->GetNormals();

	//顶点A和顶点B,计算顶点A在B切平面上的投影点
	vtkIdType aid = 0, bid = 1;
	double a[3],b[3];
	polyData->GetPoint(aid, a);
	polyData->GetPoint(bid, b);
	double normal_b[3];
	normals->GetTuple(bid, normal_b);
	//此时已经获得顶点A和B的坐标值和法向量
	double xproj[3];	//投影结果
	vtkPlane::ProjectPoint(a, b, normal_b, xporj);
	

Guess you like

Origin blog.csdn.net/qq_37366618/article/details/129944510