My name is Bart and this is my first time actually posting a question, instead of finding the solution here.
I'm currently working on a really simple plug-in for Rhino.
What it is suppose to do:
You select a structured grid of points. The plug-in groups the points based on the X location and than interpolate a NURB curve through the points.
At the moment this is my code:
var go = new Rhino.Input.Custom.GetObject();
go.SetCommandPrompt("Select All Points");
go.GeometryFilter = Rhino.DocObjects.ObjectType.Point;
go.GetMultiple(2,0);
if (go.CommandResult() != Rhino.Commands.Result.Success)
return go.CommandResult();
var o = go.Objects().Select(objRef => objRef.Point()).GroupBy(p => Math.Round (p.Location.X, 2)).ToList();
Rhino.Commands.Result rc = Rhino.Commands.Result.Success;
foreach (var ylist in o)
{
var sortedList = ylist.OrderBy(p => p.Location.Y);
Rhino.Collections.Point3dList points = new Rhino.Collections.Point3dList();
foreach (var point in sortedList)
{
Rhino.RhinoApp.WriteLine("Coordinates are: {0}, {1}, {2}", point.Location.X, point.Location.Y, point.Location.Z);
points.Add(point.Location.X, point.Location.Y, point.Location.Z);
}
//Rhino.Geometry.NurbsCurve nc = Rhino.Geometry.NurbsCurve.Create(false, 3, points);
Rhino.Geometry.Curve nc = Rhino.Geometry.Curve.CreateInterpolatedCurve(points, 3, CurveKnotStyle.Uniform);
if (nc != null && nc.IsValid)
{
if (doc.Objects.AddCurve(nc) != Guid.Empty)
{
doc.Views.Redraw();
}
else
{
rc = Rhino.Commands.Result.Failure;
}
}
}
return rc;
return Result.Success;
}
As you can see, I have tried two ways to generate the NURB curve (of which one is commented out). However, both do not have the desired outcome. I would like to fit the curve through the points (similar to the _CurveThroughPt function in Rhino) and not use the points as controlpoints.
Can somebody give me a solution or a direction? I saw an old question and solution on stackoverflow, but that was from 2009 and VB (and that function doesn't exist anymore apparently). It would be very much appreciated!!!
Best regards, Bart