algorithmic modeling for Rhino

Ramer-Douglas-Peucker and Reumann-Witkam line-simplification algorithms on C#

I would be very grateful for your help. I want to simplify the curve and I try to use grasshopper script C#. I found some algorithms to solve the task of simplification of curve using Ramer-Douglas-Peucker line-simplification algorithm on C# (


). But I don’t know how correct use it in script. Also I'm trying to compare the work of different algorithms.

Can you help me?

Views: 3336


Replies to This Discussion

I don't have Rhino installed on this computer so can't try out the GH file, but maybe this will get you started. If you're an absolute beginner, this may not be enough, so you might want to ask again.

1) Create a C# component with input of a list of Point3d

2) Copy all the code in the codeproject link (the other link is dead?) to the 'custom additional code' section near the bottom in the GH C# editor

3) In the same section, you'll need to write your own method that converts List<Point3d> to List<Point>, and another one back again. You can do this by looping through the list, and for each point, reading the X, Y, Z properties.

4) In the RunScript section, write a few lines that takes the List<Point3d> that your component accepts as input, and convert it to List<Point>. Then, you can call the DouglasPeckerReduction method from CodeProject code that you copied, using your List<Point> as a parameter. It will return another List<Point>. Convert this back to List<Point3d>. Send this to the component output.

5) To use the component, you need to convert your curve into a list of points. The easiest way to do this is using standard Grasshopper components, though if you want you can write the component to accept a curve directly, and extract the points using C# yourself. 

6) To reconstruct the curve from the C# component, use either the Polyline component or the InterpolateCurve component, depending on whether you want a simple, jagged curve or a smooth curve.

For instance:


Wait a minute: this "height" method is/was a bit ... er ... hmm

Thus, get the V2 (with some checks more)


And since you like curves ...

BTW: in some workstation in some partition in some directory there's an Opheim C# ... but where exactly (I use stupid names) it's rather a guesswork.


Also have some fun with this:


Update: Added the Reumann method.

Note: tolerance (tol) has different meaning for each method (play with the slider).


Thank you very much guys!

Now I try to understand your definitions. Has someone worked on C# with other algorithms, such as Reumann-Witkam or Opheim?

Incidentally the Polyline Reduction component uses Douglas Puecker already.

Update: Added a few lines more


BTW: with regard your specific requirement mailed:

1. Find the appropriate points on the curve (i.e. your desired "points to keep" at any cost):

2. Use some method and find the reduced Pts.

3. Then add the Pts from 1 to the List 2 of reduced Points.

4. Sort the List VS the curve (or use some smart way to properly "insert" Pts from 1 to  Pts from 2).

public List<Point3d> SortPointsAlongCurve(List<Point3d> points_list, Curve sorting_curve)
    points_list.Sort((point1, point2) =>
      double point1_t = 0;
      double point2_t = 0;
      sorting_curve.ClosestPoint(point1, out point1_t);
      sorting_curve.ClosestPoint(point2, out point2_t);
      return point2_t.CompareTo(point1_t);
    return points_list;


public List<Point3d> SortPointsAlongCurve2(List<Point3d> pList, Curve curve)
    List<Point3d> pSorted = new List<Point3d>();
    List<Point3d> pClosest = new List<Point3d>();

    for(int i = 0; i < pList.Count;i++){
      double t;
      curve.ClosestPoint(pList[i], out t);

    Point3d pPrev = pClosest[0];
    Rhino.Collections.Point3dList points = new Rhino.Collections.Point3dList(pClosest.Skip(1).ToList());

    for(int i = 1; i < pClosest.Count;i++){

      int ind = points.ClosestIndex(pPrev);
      Point3d pNext = points[ind];
      pPrev = pNext;
      if(i == pClosest.Count - 1) pSorted.Add(pPrev);
    return pSorted;

5. Do some Polyline or Nurbs .

Peter, thank you for your help! I'll be comprehend your advices.






  • Add Photos
  • View All

© 2021   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service