Grasshopper

algorithmic modeling for Rhino

Hey guys,

I am currently trying to build custom components, and I have a question regarding performance.

The component basically divides curve A into 30 points, checks the closest distance to curve B from each point and sums all the distances.

When I run the custom component, it takes much more time to run than the same logic built in GH. Does anyone know why?

And, does anyone have suggestions to speed up the custom component?

Thanks in advance,

Jeroen

Views: 395

Attachments:

Replies to This Discussion

Curve.DivideEquidistant is a slow method. It measures the distance between adjacent division parameters in XYZ space, which basically means it has to intersect the curve with a sphere for each point. Try Curve.DivideByCount

private double ComputeAreaSum(Curve c1, Curve c2)
{
  Point3d[] points;
  c1.DivideByCount(30, true, out points);

  double sumDistance = 0;
  foreach (Point3d pt in points)
  {
    double parameter;
    c2.ClosestPoint(pt, out parameter);

    double distance = pt.DistanceTo(c2.PointAt(parameter));
    sumDistance += distance;
  }
  return sumDistance;
}

Thank you, will try this. Much appreciated!

Jeroen

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service