Loose fit BoundingBox

Why am I getting a extended bounding box for a plane surface. I am generating the box for a plane surface. Is there a way to get tight bounding box?
MicrosoftTeams-image (34)
Here is the C# script I am using.

RhinoDoc activeDoc = RhinoDoc.ActiveDoc;
    IEnumerable<RhinoObject> brepObjects1 = activeDoc.Objects.GetObjectList(ObjectType.Brep);
    RhinoObject object1 = brepObjects1.ElementAt(0);
    Brep body = Brep.TryConvertBrep(object1.Geometry);

    Point3d Centroid = body.GetBoundingBox(true).Center;


    List<BoundingBox> boxes = new List<BoundingBox>();
    List<string> points = new List<string>();

    foreach (BrepFace surface in body.Faces)
    {
      List<Point3d> point = new List<Point3d>();
      BoundingBox box = surface.GetBoundingBox(true);
      boxes.Add(box);
      Point3d max = box.Max;
      Point3d min = box.Min;

      Vector3d offset = new Vector3d(Centroid.X, Centroid.Y, Centroid.Z);
      Point3d point1 = Point3d.Subtract(min, offset);
      Point3d point2 = Point3d.Subtract(max, offset);

      points.Add(point1.ToString() + "\n" + point2.ToString());

    }

Can you share the 3dm or a similar simple one demonstrating the problem?

Sometimes, the underlying brep face surface can act as if it’s untrimmed to the edges of the brep.

Is there a chance that that’s the bounding box of the surface before it was incorporated into the brep?

If so, you may be able to do some operations to get the effectively trimmed surface- perhaps by something like copying (so you don’t lose the original) then exploding.

Sure here is the file.
cube (1).3dm (54.8 KB)

Your initial pic and comments talk about a planar surface, presumably the red one.

This file is named cube (1) but appears to be a cylinder with the rounded extrusion meeting the y axis (y axis perpendicular to the red plane in your original pic).

Is there a chance that you’re grabbing the cylinder surface not one of the planes on the end of the cylinder when getting the bounding box you screenshotted?

Edit to add: one further note- the bounding box of the cylinder end is showing as planar for me.

Sorry I mistakenly sent the wrong file.
Please find the cube file below
cube (1).stp (13.3 KB)

Even in the case of cylinder ,the top and bottom plane surface has not-fit bounding box.

Oh, I thought in your initial post that the plane was the surface you were trying to use and the box was the bounding box you were getting.

When I look at either end of your cylinder, I’m seeing a circle with radius 10 centered on 0 and a bounding box with correct points for that:
|Bounding Box Min||-10.000|-10.000|0.000|
|Bounding Box Max||10.000|10.000|0.000|
And one at z=15 for the other end.

Is it really the bounding box you’re asking about or the way Rhino highlights a slightly larger plane when you select that face? Also, if I select the face of the actual extrusion, then I get a circle as expected. It’s only if I convert to a brep that I get the visual effect- but the bounding box you’re reporting still works fine for me.

Hi Nathan
I for the lateral curved surface I could get a fit bounding box, I am getting extended box for the two plane surfaces in cylinder as well as all the surfaces in cube.

Hi @Rushank ,

Upon reviewing your file I noticed that the NURBS surfaces have noot been shrunk. This discrepancy is causing the issue you’re experiencing. The bounding box you’re seeing represents the untrimmed surface. In NURBS geometry you must shrink the surface post-trimming to realign the control point grid accurately with the modified shape.

In brief: Execute the “ShrinkTrimmedSrf” command prior to using the bounding box function.

To elaborate NURBS surfaces are defined by a control point grid. When these surfaces are trimmed, the original, larger NURBS surface often remains beyond the trimmed area, invisible but still present.

The problem isnt with the bounding box command itself as it accurately matches the underlying NURBS structure. The issue arises because this structure hasnt been updated to match your visual modifications leading to a bounding box that appears oversized but is, in fact, accurate to the unaltered NURBS surface.

Hope this clarifies things, It will 100% solve your issue.
Best regards,
Farouk

When I run your code with the cylinder model, there are zero objects in brepObjects1.

That makes sense because it’s an extrusion, not a brep object.

Are you supplying the full story here?
Here’s what I did to run your code: add some using’s and add a console writeline with the count of the collection before it tries to access an element.

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Rhino;
using Rhino.Geometry;
using Rhino.DocObjects;

Console.WriteLine("Testing CS");

RhinoDoc activeDoc = RhinoDoc.ActiveDoc;
    IEnumerable<RhinoObject> brepObjects1 = activeDoc.Objects.GetObjectList(ObjectType.Brep);
    Console.WriteLine("Number of objects: " + brepObjects1.Count());
    RhinoObject object1 = brepObjects1.ElementAt(0);
    Brep body = Brep.TryConvertBrep(object1.Geometry);

    Point3d Centroid = body.GetBoundingBox(true).Center;


    List<BoundingBox> boxes = new List<BoundingBox>();
    List<string> points = new List<string>();

    foreach (BrepFace surface in body.Faces)
    {
      List<Point3d> point = new List<Point3d>();
      BoundingBox box = surface.GetBoundingBox(true);
      boxes.Add(box);
      Point3d max = box.Max;
      Point3d min = box.Min;

      Vector3d offset = new Vector3d(Centroid.X, Centroid.Y, Centroid.Z);
      Point3d point1 = Point3d.Subtract(min, offset);
      Point3d point2 = Point3d.Subtract(max, offset);

      points.Add(point1.ToString() + "\n" + point2.ToString());

    }

Thank you guys for help.
After using ShrinkSurfaceToEdge() I could get fitting bounding box.

Glad I could help. That was a tricky one if you didnt know it.
Have a great day !