Grasshopper

algorithmic modeling for Rhino

Hi! I recently face a weird problem when trying to do brep methods. The brep is from flat bounding box.

  1. Curve planarcurve = c; 
  2. BoundingBox bbox= planarcurve.GetBoundingBox(true);
  3. Brep b_bbox = bbox.ToBrep();
  4. Print(b_bbox .ToString()); //_________ this line gives me error 
  5. double d = b_bbox.GetArea();//______ same error

The error says: Object reference not set to an instance of an object. (line: 4) The goal is to get the area of the flat bounding box.

Any advice is appreciated! Thanks

Views: 886

Replies to This Discussion

Here is the screenshot of the problem. I need to do area calculation of the flat boundingbox in C#. 

Update 1.

Figured out a "temporary" way of solving it by making Polyline of the flat box vertices. Pretty sure it only works to calculate base area of the bounding box. Any advice is appreciated :) 

  1. Curve planarcurve = x;
  2. BoundingBox bbox = planarcurve.GetBoundingBox(true);
  3. Point3d[] pts = bbox.GetCorners();

  4. Point3d[] pt_ar = new Point3d[5]{pts[0],pts[1],pts[2],pts[3],pts[0]};

  5. Polyline plln = new Polyline(pt_ar);

  6. Brep b_bbox = Brep.CreatePlanarBreps(plln.ToNurbsCurve())[0];
  7. A = b_bbox.GetArea(); //works now

A flat boundingbox would result in an invalid brep, because four of the six sides would have zero area and coincident edges. Grasshopper specifically handles this case and creates a single plane surface instead.

However you can calculate the area of a boundingbox far more efficiently than from a brep. If you know your box is flat, all you have to do is multiply the difference in X and Y of the Min and Max points.

Wow that is nifty. Thanks David! 

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