opencascade 計算點與TopoDS_Shape中各個點的距離

 下面自己總結的 計算點與TopoDS_Shape中各個點的距離的代碼,輸入爲gn_Pnt類型的點
//DesPnt 爲輸入
 	TopExp_Explorer Ex; 
	Standard_Real MinDisance = 1e+10;
	Standard_Real CurDisance = 0.0;
	gp_Pnt current,ResPnt;

	for (Ex.Init(S,TopAbs_VERTEX); Ex.More(); Ex.Next()) { 
	
	TopoDS_Vertex currentVt = TopoDS::Vertex(Ex.Current());
	current = BRep_Tool::Pnt(currentVt);
	CurDisance = current.Distance(DesPnt);
	if(CurDistance<MinDistance){
	  MinDistance = CurDistance;
	  ResPnt = current;
	  }
	  
	} 

	return ResPnt;
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章