Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

developer:rhinocommonsamples:sortpoints [2015/09/14] (current)
Line 1: Line 1:
 +===== Sample: Sorting 3D points =====
 +
 +===== C# =====
 +<code c#>
 +public class SortPointsCommand : Command
 +{
 +  public override string EnglishName { get { return "​csSortPoints";​ } }
 +
 +  protected override Result RunCommand(RhinoDoc doc, RunMode mode)
 +  {
 +    var points = new List<​Point3d>​
 +    {
 +      new Point3d(0, 0, 0),
 +      new Point3d(0, 0, 1),
 +      new Point3d(0, 1, 0),
 +      new Point3d(0, 1, 1),
 +      new Point3d(1, 0, 0),
 +      new Point3d(1, 0, 1),
 +      new Point3d(1, 1, 0),
 +      new Point3d(1, 1, 1)
 +    };
 +
 +    RhinoApp.WriteLine("​Before sort ...");
 +    foreach (var point in points)
 +      RhinoApp.WriteLine("​point:​ {0}", point);
 +
 +    var sorted_points = Point3d.SortAndCullPointList(points,​ doc.ModelAbsoluteTolerance);​
 +
 +    RhinoApp.WriteLine("​After sort ...");
 +    foreach (var point in sorted_points)
 +      RhinoApp.WriteLine("​point:​ {0}", point);
 +
 +    doc.Objects.AddPoints(sorted_points);​
 +    doc.Views.Redraw();​
 +    return Result.Success;​
 +  }
 +}
 +</​code>​
 +===== VB.NET =====
 +<code vb>
 +Public Class SortPointsCommand
 +  Inherits Command
 +  Public Overrides ReadOnly Property EnglishName() As String
 +    Get
 +      Return "​vbSortPoints"​
 +    End Get
 +  End Property
 +
 +  Protected Overrides Function RunCommand(doc As RhinoDoc, mode As RunMode) As Result
 +    Dim points = New List(Of Point3d)() From { _
 +      New Point3d(0, 0, 0), _
 +      New Point3d(0, 0, 1), _
 +      New Point3d(0, 1, 0), _
 +      New Point3d(0, 1, 1), _
 +      New Point3d(1, 0, 0), _
 +      New Point3d(1, 0, 1), _
 +      New Point3d(1, 1, 0), _
 +      New Point3d(1, 1, 1) _
 +    }
 +
 +    RhinoApp.WriteLine("​Before sort ...")
 +    For Each point As Point3d In points
 +      RhinoApp.WriteLine("​point:​ {0}", point)
 +    Next
 +
 +    Dim sorted_points = Point3d.SortAndCullPointList(points,​ doc.ModelAbsoluteTolerance)
 +
 +    RhinoApp.WriteLine("​After sort ...")
 +    For Each point As Point3d In sorted_points
 +      RhinoApp.WriteLine("​point:​ {0}", point)
 +    Next
 +
 +    doc.Objects.AddPoints(sorted_points)
 +    doc.Views.Redraw()
 +    Return Result.Success
 +  End Function
 +End Class
 +d Namespace
 +</​code>​
 +===== Python =====
 +<code python>
 +import System.Collections.Generic;​
 +import Rhino;
 +from Rhino.Commands import Result
 +from Rhino.Geometry import Point3d
 +from scriptcontext import doc
 +
 +def RunCommand():​
 +  points = [Point3d(0, 0, 0), Point3d(0, 0, 1), Point3d(0, 1, 0), 
 +    Point3d(0, 1, 1), Point3d(1, 0, 0), Point3d(1, 0, 1), 
 +    Point3d(1, 1, 0), Point3d(1, 1, 1)]
 +
 +  print "​Before sort ..."
 +  for point in points:
 +    print "​point:​ {0}"​.format(point)
 +
 +  sorted_points = Point3d.SortAndCullPointList(
 +      points, doc.ModelAbsoluteTolerance);​
 +
 +  print "After sort ..."
 +  for point in sorted_points:​
 +    print "​point:​ {0}"​.format(point)
 +
 +  doc.Objects.AddPoints(sorted_points);​
 +  doc.Views.Redraw();​
 +  return Result.Success;​
 +
 +if __name__ == "​__main__":​
 +  RunCommand()
 +</​code>​
 +
 +{{tag>​Developer rhinocommon}}
  
developer/rhinocommonsamples/sortpoints.txt ยท Last modified: 2015/09/14 (external edit)