Getting the position of a point on a brep


#1

Hi,

I want to know if a determined point is in Right, left, front, behind… of a brep

For example, in the next Image the green lines are in brep’s front face.

I think that if I calculate normal’s brep in the point I get (0, -1, 0) and I set that value to the front face

But with an irregular breps this method doesn’t work.

Do you know any form to determine easy the brep’s face given a point?

I’m working with c# and RhinoCommon


(Menno Deij - van Rijswijk) #2

Use the ClosestPoint method that returns a omponent index. This index tells you which BrepFace is closest. Also you get u, v, normal and distance.

http://4.rhino3d.com/5/rhinocommon/html/M_Rhino_Geometry_Brep_ClosestPoint_1.htm


(Dale Fugier) #3

A function like this might also be helpful:

static BrepFace BrepFaceFromPoint(Brep brep, Point3d testPoint)
{
  BrepFace closest_face = null;
  if (null != brep && testPoint.IsValid)
  {
    double closest_dist = RhinoMath.UnsetValue;
    foreach (BrepFace face in brep.Faces)
    {
      double u, v;
      if (face.ClosestPoint(testPoint, out u, out v))
      {
        Point3d face_point = face.PointAt(u, v);
        double face_dist = face_point.DistanceTo(testPoint);
        if (!RhinoMath.IsValidDouble(closest_dist) || face_dist < closest_dist)
        {
          closest_dist = face_dist;
          closest_face = face;
        }
      }
    }
  }
  return closest_face;
}