Dear McNeel - maybe @dale can help
I am getting some unexpected results from Brep.ClosestPoint in Rhinocommon c#
Rhino 7, Version 7 SR5 (7.5.21100.3001, 2021-04-10), Windows 10
error_extract_brepclosest_point.3dm (65.5 KB)
i would expect, that the closest point is the Brep-Vertex. (and geometrical it is)
results:
closestPoint - as expected
But
(1) the ComponentIndexType claims it is a face. But it should be a BrepVertex
(2) if it was Face, the normal should point somehow vertical to one face - but i am not sure where the normal-direction comes from / relates to.
the follow code / command roughly extracts the error-part
PR_BrepClosestPtError.cs (2.6 KB)
protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
// get Surface
const ObjectType filter = ObjectType.Surface | ObjectType.Brep;
Rhino.DocObjects.ObjRef objref;
Rhino.Commands.Result rc = Rhino.Input.RhinoGet.GetOneObject("Select Brep", false, filter, out objref);
if (rc != Rhino.Commands.Result.Success || objref == null)
return rc;
Brep srfB = objref.Brep();
if (srfB == null) return Result.Failure;
// get Point
GetPoint gp = new Rhino.Input.Custom.GetPoint();
gp.SetCommandPrompt("Point to evaluate");
OptionDouble oLength = new OptionDouble(100, true, 1);
gp.AddOptionDouble("LineLength", ref oLength);
gp.Get();
if (gp.CommandResult() != Rhino.Commands.Result.Success)
return gp.CommandResult();
// get values from input
Point3d pt0 = gp.Point();
double length = oLength.CurrentValue;
// closest Point returnvalues
Point3d closestPt = Point3d.Unset;
Vector3d normal = Vector3d.Unset;
ComponentIndex ci;
double s;
double t;
// query
bool result = srfB.ClosestPoint(pt0, out closestPt, out ci, out s, out t, 0, out normal);
if (!result) return Result.Failure;
RhinoApp.WriteLine("componentIndexType is {0}", ci.ComponentIndexType.ToString());
if (ci.ComponentIndexType != ComponentIndexType.BrepVertex)
{
normal.Unitize(); // not sure if nesscessary
Line feedbackLine = new Line(closestPt, closestPt + length * normal);
doc.Objects.AddLine(feedbackLine);
doc.Views.Redraw();
}
return Result.Success;
}
is this a bug ? some tolerance problem ?
i will code a workarround, to query if the resulting point is close to one vertice - so if it is a deeper problem, no hurry … if i did something wrong, would be happe to know what.
Thanks. -tom