当前位置: 首页>>代码示例>>C++>>正文


C++ gp_Pnt::SquareDistance方法代码示例

本文整理汇总了C++中gp_Pnt::SquareDistance方法的典型用法代码示例。如果您正苦于以下问题:C++ gp_Pnt::SquareDistance方法的具体用法?C++ gp_Pnt::SquareDistance怎么用?C++ gp_Pnt::SquareDistance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gp_Pnt的用法示例。


在下文中一共展示了gp_Pnt::SquareDistance方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: projected

PointOnFacesProjector::Result PointOnFacesProjector::projected(const gp_Pnt& point) const
{
  // Find the closest node in the triangulations
  internal::NodeBndBoxSelector selector(point);
  if (d->m_ubTree.Select(selector) <= 0)
    return PointOnFacesProjector::Result();

  const int minNodeId = selector.minDistanceNodeIndex().first;
  const Handle_Poly_Triangulation& triangulation = selector.minDistanceNodeIndex().second;

  // Find the triangle where distance is minimum
  const TColgp_Array1OfPnt& nodes = triangulation->Nodes();
  const Poly_Array1OfTriangle& triangles = triangulation->Triangles();
  double minDist = std::numeric_limits<double>::max();
  const Poly_Triangle* minTriangle = NULL;
  gp_Pnt projectedPnt;
  for (int iTri = triangles.Lower(); iTri <= triangles.Upper(); iTri++) {
    const Poly_Triangle& t = triangles(iTri);
    int n1, n2, n3;
    t.Get(n1, n2, n3);
    if (minNodeId == n1 || minNodeId == n2 || minNodeId == n3) {
      const std::pair<gp_Pnt, bool> projPntInfo = math::projectPointOnTriangle(point,
                                                                               nodes(t(1)),
                                                                               nodes(t(2)),
                                                                               nodes(t(3)));
      const double dist = point.SquareDistance(projPntInfo.first);
      if (dist < minDist) {
        minTriangle = &t;
        minDist = dist;
        projectedPnt = projPntInfo.first;
      }
    }
  }

  if (minTriangle != NULL) {
    const TopoDS_Face* face = d->triangulationToFace(triangulation);
    const TopAbs_Orientation faceOrientation = face != NULL ? face->Orientation() : TopAbs_FORWARD;
    const gp_Vec triNormal = occ::MathTools::triangleNormal(nodes, *minTriangle, faceOrientation);
    return PointOnFacesProjector::Result(face != NULL ? *face : TopoDS_Face(),
                                         projectedPnt,
                                         triNormal);
  }
  return PointOnFacesProjector::Result();
}
开发者ID:joukeHijlkema,项目名称:fougtools,代码行数:44,代码来源:point_on_faces_projector.cpp


注:本文中的gp_Pnt::SquareDistance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。