2013-09-25 51 views
1

我的名字是巴特,這是我第一次實際發佈一個問題,而不是在這裏找到解決方案。_CurveThroughPt rhino3d SDK(C#)

我目前正在研究一個非常簡單的Rhino插件。

它應該做什麼:

您選擇一個結構化點網格。插件根據X位置對點進行分組,並通過點插入NURB曲線。

目前,這是我的代碼:

 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; 
    } 

正如你所看到的,我已經嘗試了兩種方法來生成NURB曲線(其中一個被註釋掉)。但是,兩者都沒有預期的結果。我想通過點擬合曲線(類似於Rhino中的_CurveThroughPt函數),而不是將這些點用作控制點。

有人可以給我一個解決方案或方向嗎?我在stackoverflow上看到了一個老問題和解決方案,但那是從2009年和VB(並且該功能顯然不再存在)。這將是非常感謝!

最好的問候,巴特

回答

0

顯然,一些調試過程中出了錯,並且新的代碼未加載到犀牛。

確實,CreateInterpolatedCurve與Rhino中的_CurveThroughPt函數給出了相同的結果。

此致敬禮 巴特