Closest point to trimmed surface

Hello :slightly_smiling_face:
I’m developing plug-in (c++)

I need to find the closest point on a surface to another arbitrary point.
I’m using GetClosestPoint(), but it finds the point on the whole (untrimmed) surface.
Is there a way to find the closest point on visible part of surface?

Thanks in advance for any help you can provide!

A trimmed surface is always a boundary representation, a.k.a. B-rep (i.e. of type ON_Brep). So, you need an ON_Brep object, and then you can use RhinoBrepClosestPoint(...), defined in the header rhinoSdkUtilities.h

1 Like

Thank you for the response
But here the results of RhinoBrepClosestPoint function (input: blue; result: green)

So it seems like I have to determine such wrong points somehow and for them calculate closest points to brep’s trim curve (somehow extracted 3d trim curve)
Am I on the a proper way?

With the code below, I get the following:

  CRhinoGetObject go;
  go.SetCommandPrompt(L"Select BRep");

  go.SetGeometryFilter(CRhinoGetObject::GEOMETRY_TYPE_FILTER::polysrf_object | 

  CRhinoGet::result gr = go.GetObjects(1, 1);
  if (go.CommandResult() != CRhinoCommand::result::success)
    return go.CommandResult();

  auto brep = go.Object(0).Brep();
  if (!brep)
    return success;

  for(int x = 0; x < 10; ++x)
    ON_3dPoint pt(x,0,0);
    ON_3dPoint closest;
    double s, t;
    if (RhinoBrepClosestPoint(*brep, pt, &ci, &s, &t, &closest ))

  return CRhinoCommand::success;

Thank you so much!
My problem was in the way I’m getting/modifying Brep