How to make a bounding rectangle with C#

Is there a way to do with C# the same that the Plane Through Shape component does?

The Plane Through Shape component is C#, so yes, it’s possible.

Do you want to create a plane that extends beyond the boundingbox of the shape as a whole, or do you want to create the smallest possible plane which is still bigger than the specific section?

I would like to do exactly the same: a function that receives the shape, the plane and the boundary inflation and returns the rectangle. Is there already a function to do that?

I think it is

  1. Get bounding box of object
  2. Inflate bounding box (parameter t)
  3. Move plane to center of bbox
  4. Intersect plane with bbox
  5. Move that intersection curve back to original plane
1 Like

The quick way is to get the bounding-box of the shape, project all 8 corners onto the plane (s,t) space, find the lowest and highest s and t values, then use those to create a Rectangle3d based on your plane. This will give you a rectangle which is guaranteed not smaller than your shape. It could however still be much larger than it needs to be. If you want to shrink it, you’ll have to perform an intersection between your plane and your shape and find the boundingbox of only the intersection points/curves. That will give you the smallest possible rectangle.

1 Like

Thanks a lot. I’ll try that.

For anyone that still has the same question, this seemed to work for me:

    BoundingBox bb = new BoundingBox();

    for (int i = 0; i<items.Count; i++) bb.Union(crv[i].GetBoundingBox(false));

    Plane pl = new Plane(bb.GetCorners()[0], bb.GetCorners()[1], bb.GetCorners()[2]);

    Rectangle3d rect = new Rectangle3d(pl, bb.Min, bb.Max);

    A = rect;