Question about the TextGeometry.GetBoundingBox(plane) method

I use TextObject. TextGeometry. GetBoundingBox (plane) method to create BoundingBox has some problems.BoundingBox is not the correct border of TextObject.as the picture shows.Is this a bug?
Thank you for all the suggestions.

my file:
textBoundingbox.gh (2.0 KB)

text boundingbox.3dm (57.2 KB)

Hi @603419608,

This seems to work:

var bbox = text.TextGeometry.GetBoundingBox(true);

– Dale

HI dale
var bbox = text.TextGeometry.GetBoundingBox(true)is working.;But this is not what I want.The GH component generates the result I want.

2018-12-18-textBoundingbox.gh (3.1 KB)

When you get the bounding box for a piece of geometry, you can specify a transformation. The bounding box component allows you to input a plane, which is used to ChangeBasis or Orient transform which is then used inside the bounding box calculation.

I’m on an iPad right now so can’t do better than that…

Thank you david,But it’s still not correct. Is there anything wrong with my code?
Thanks


2018-12-19-textBoundingbox.gh (2.1 KB)

I think the order of your planes in the ChangeBasis call is wrong. My own personal mnemonic for ChangeBasis is that it’s always the other way around than you think.

Do note a bounding box itself has no orientation, it’s just two corner points. So if you want to see your box oriented correctly, you’ll have to convert it into a Box3d and transform it back.

1 Like

Thank you david,The location of the BoundingBox is correct.But BoundingBox is larger than TextGeometry.
like this:

,I don’t know if it is a problem with the TextObject.TextGeometry.GetBoundingBox(transform) method.

I used another method to find the results I wanted.

code1:
private void RunScript(Guid guid, ref object A)
{

    var text = Rhino.RhinoDoc.ActiveDoc.Objects.Find(guid) as Rhino.DocObjects.TextObject;
    if(text != null)
    {
      BoundingBox empty = BoundingBox.Empty;
      var textPlane = text.TextGeometry.Plane;
      Transform transform = Transform.ChangeBasis(Plane.WorldXY, textPlane);
      var bbox = text.TextGeometry.GetBoundingBox(transform);
      empty.Union(bbox);
      Box box = new Box(textPlane, new Interval(bbox.Min.X, bbox.Max.X), new Interval(bbox.Min.Y, bbox.Max.Y), new Interval(bbox.Min.Z, bbox.Max.Z));
      A = box;
      this.Component.ExpireSolution(true);
    }

  }

code2:

private void RunScript(Guid guid, ref object A)
{

var text = Rhino.RhinoDoc.ActiveDoc.Objects.Find(guid) as Rhino.DocObjects.TextObject;
if(text != null)
{
  A = TextBoundingBox(text);
  this.Component.ExpireSolution(true);
}

}

  private Rectangle3d TextBoundingBox(Rhino.DocObjects.TextObject text)
  {
    BoundingBox empty = BoundingBox.Empty;
    var textPlane = text.TextGeometry.Plane;
    Transform transform = Transform.ChangeBasis(Plane.WorldXY, textPlane);
    var curves = text.TextGeometry.Explode();
    foreach(var curve in curves)
    {
      BoundingBox bbox = curve.GetBoundingBox(transform);
      empty.Union(bbox);
    }
    return new Rhino.Geometry.Rectangle3d(textPlane, new Interval(empty.Min.X, empty.Max.X), new Interval(empty.Min.Y, empty.Max.Y));

  }