Grasshopper

algorithmic modeling for Rhino

Hello,

A question about the DivideByCount for multiple curves in c#.  I've not been successful in outputting points for a list of curves. I am having difficulty knowing how to implement the method and have placed my code below. The issue is that I return only the set of points that belong to the last curve.

Point3d[] points = new Point3d[numberOfEdges];  

//numberOfEdges previously determined

for (int i = 0; i < numberOfEdges; i++)

{

curve[i].DivideByCount(5, true, out points); //collect points

}

My natural inclination would be to write the 'collect points' line differently (as below) but am having problems with the method.

Point3d[] points = new Point3d[numberOfEdges];  

//numberOfEdges previously determined

for (int i = 0; i < numberOfEdges; i++)

{

points[i] = curve[i].DivideByCount(5, true); //collect points

}

Does anyone know how to solve this?

Views: 441

Replies to This Discussion

List<Point3d> points = new List<Point3d>();

for (int i = 0; i < numberOfEdges; i++)

{

  Point3d[] localPoints;

  curve[i].DivideByCount(5, true, out points);

  points.AddRange(localPoints);

}

--

David Rutten

david@mcneel.com

David,

Thank you for the example.  I have another question based on your preference for using lists over arrays. What would be the best technique for returning the points as a tree so that the points along each line can be distinguished from one another?

I've been playing around with DataTree but haven't have only been able to produce trees that output items like "Rhino.Geometry.Point3d[]" rather than the point data itself (ie. (x,y,z)).

DataTree<Point3d> points = new DataTree<Point3d>();

for (int i = 0; i < numberOfEdges; i++)

{

  Point3d[] localPoints;

  curve[i].DivideByCount(5, true, out points);

  points.AddRange(localPoints, new GH_Path(i));

}

--

David Rutten

david@mcneel.com

David,

Many thanks however the code raises some questions and I'm curious because for some reason I've been receiving an overloaded method error which seems to stem from the line "curve[i].DivideByCount(5, true, out points);"

I haven't yet worked out the alterations required to make the tree method work but the list method seems to work with these alterations below. I'm not sure why the code has needed to be altered but would be thankful for any suggestions you have (suggestions for the tree method in particular).

int divisor = 5;

Point3d[] localPoints = new Point3d[divisor];

List<Point3d> allPoints = new List<Point3d>();

for (int i = 0; i < numberOfEdges; i++)

{

curve[i].DivideByCount(divisor, true, out localPoints);

allPoints.AddRange(localPoints);

}

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service