Class: Geom::BoundingBox

Inherits:
Object
  • Object
show all

Overview

Note:

that the bounding box returned for face-me components is the center of its entire range of motion. This behavior changed in SketchUp 7.1. In 7.0 and earlier, the .bounds method would return the bounds around the face-me component's current, visible center.

Bounding boxes are three-dimensional boxes (eight corners), aligned with the global axes, that surround entities within your model. There is a default bounding box for any new model that will surround all entities, including all groups and components. Additionally, there are bounding boxes for Drawingelement objects, including components and groups. Bounding boxes are only large enough to exactly bound the entities within your model, group, or component.

You can also create arbitrary BoundingBox objects by calling BoundingBox.new.

Examples:

# You can get the bounding box on a model.
model = Sketchup.active_model
model_bb = model.bounds

# Or you can get the bounding box on any Drawingelement object.
first_entity = model.entities[0]
first_entity_bb = first_entity.bounds

# Or you can create an empty bounding box of your own.
boundingbox = Geom::BoundingBox.new

Version:

  • SketchUp 6.0

Instance Method Summary # collapse

  • #add(*args) ⇒ Object

    The add method is used to add a point, vertex, or other bounding boxes to the bounding box.

  • #center ⇒ Object

    The center method is used to retrieve the Point3d object at the center of the bounding box.

  • #clear ⇒ Object

    The clear method is used to clear a bounding box.

  • #contains?(point_or_bb) ⇒ Object

    This method is used to determine if a bounding box contains a specific Point3d or BoundingBox object.

  • #corner(corner_index) ⇒ Object

    The corner method is used to retrieve a point object at a specified corner of the bounding box.

  • #depth ⇒ Object

    The depth method is used to retrieve the depth of the bounding box.

  • #diagonal ⇒ Object

    The diagonal method is used to get the length of the diagonal of the bounding box.

  • #empty? ⇒ Object

    The empty? method is used to determine if a bounding box is empty (such as if the bounds have not been set.) This returns the opposite of the valid? method.

  • #height ⇒ Object

    The height method is used to retrieve the height of the bounding box.

  • #initialize ⇒ Object constructor

    The new method is used to create a new, empty, bounding box.

  • #intersect(boundingbox) ⇒ Object

    The intersect method is used to retrieve a bounding box that is the result of intersecting one bounding box with another.

  • #max ⇒ Object

    The max method is used to retrieve the Point3d object where x, y and z are maximum in the bounding box.

  • #min ⇒ Object

    The min method is used to retrieve the Point3d where x, y and z are minimum in the bounding box.

  • #valid? ⇒ Object

    The valid method is used to determine if a bounding box is valid (contains points).

  • #width ⇒ Object

    The width method is used to retrieve the width of the bounding box.

Constructor Details

#initializeObject

The new method is used to create a new, empty, bounding box.

Examples:

boundingbox = Geom::BoundingBox.new

Version:

  • SketchUp 6.0

Instance Method Details

#add(point_or_bb) ⇒ Object #add(points_or_bb) ⇒ Object

The add method is used to add a point, vertex, or other bounding boxes to the bounding box. The size of the bounding box will increase as necessary to accommodate the new items.

Adding one point to an empty bounding box does not increase the size of the bounding box. You must add at least two points before methods such as BoundingBox.diagonal will return a size greater than zero.

Examples:

model = Sketchup.active_model
boundingbox = model.bounds
point1 = Geom::Point3d.new(100, 200, 300)
point2 = Geom::Point3d.new(200, 400, 200)
boundingbox.add(point1, point2)

Overloads:

Returns:

  • boundingbox - the new, resized, BoundingBox object if successful

Version:

  • SketchUp 6.0

#centerObject

The center method is used to retrieve the Point3d object at the center of the bounding box.

Examples:

boundingbox = Geom::BoundingBox.new
boundingbox.add([100, 200, -400], [200, 400, 100])
# This will return a point Point3d(150, 300, -150).
point = boundingbox.center

Returns:

  • point - the Point3d at the center of the bounding box if successful

Version:

  • SketchUp 6.0

#clearObject

The clear method is used to clear a bounding box.

A cleared BoundingBox does not have a size greater than zero until you add at least two points or another bounding box.

Examples:

boundingbox = Geom::BoundingBox.new
boundingbox.add([100, 200, -400], [200, 400, 100])

# This will return false.
boundingbox.empty?

boundingbox.clear
# This will return true.
boundingbox.empty?

Returns:

  • boundingbox - the BoundingBox object which was cleared

Version:

  • SketchUp 6.0

#contains?(point_or_bb) ⇒ Object

This method is used to determine if a bounding box contains a specific Point3d or BoundingBox object.

Examples:

boundingbox = Geom::BoundingBox.new
boundingbox.add([100, 200, -400], [200, 400, 100])
# This will return false.
boundingbox.contains?([300, 100, 400])
# This will return true.
boundingbox.contains?([150, 300, -200])

Returns status - true if successful (bounding box contains a Point3d or BoundingBox object), or false if unsuccessful.

Parameters:

Returns:

  • status - true if successful (bounding box contains a Point3d or BoundingBox object), or false if unsuccessful.

Returns:

  • (Boolean)

Version:

  • SketchUp 6.0

#corner(corner_index) ⇒ Object

The corner method is used to retrieve a point object at a specified corner of the bounding box.

There are 8 corners to a bounding box, identified by the numbers 0 through 7. Points are returned in the currently set units (inches, by default). These are which index refers to which corner:

- 0 = [0, 0, 0] (left front bottom)
- 1 = [1, 0, 0] (right front bottom)
- 2 = [0, 1, 0] (left back bottom)
- 3 = [1, 1, 0] (right back bottom)
- 4 = [0, 0, 1] (left front top)
- 5 = [1, 0, 1] (right front top)
- 6 = [0, 1, 1] (left back top)
- 7 = [1, 1, 1] (right back top)

Examples:

boundingbox = Geom::BoundingBox.new
boundingbox.add([100, 200, -400], [200, 400, 100])
# This will return Point3d(100, 200, -400).
boundingbox.corner(0)
# This will return Point3d(100, 200, -400).
boundingbox.corner(6)

Returns point - a Point3d object if successful

Parameters:

  • corner_index

    A number (from 0 to 7) representing point at the corner you want to retrieve.

Returns:

  • point - a Point3d object if successful

Version:

  • SketchUp 6.0

#depthObject

The depth method is used to retrieve the depth of the bounding box.

The depth is returned in the currently set units (inches, by default).

Examples:

boundingbox = Geom::BoundingBox.new
boundingbox.add([100, 200, -400], [200, 400, 100])
# This will return a Length of 500.0.
length = boundingbox.depth

Returns:

  • depth - the depth of the bounding box if successful

Version:

  • SketchUp 6.0

#diagonalObject

The diagonal method is used to get the length of the diagonal of the bounding box.

The diagonal is returned in the currently set units (inches, by default).

Examples:

boundingbox = Geom::BoundingBox.new
boundingbox.add([100, 200, -400], [200, 400, 100])
# This will return a point a Length of ~547.72.
length = boundingbox.diagonal

Returns:

  • diagonal - the size of the diagonal for the bounding box if successful

Version:

  • SketchUp 6.0

#empty?Object

The empty? method is used to determine if a bounding box is empty (such as if the bounds have not been set.) This returns the opposite of the valid? method.

Examples:

boundingbox = Geom::BoundingBox.new
boundingbox.add([100, 200, -400], [200, 400, 100])
# This will return false.
boundingbox.empty?

Returns:

  • status - true if the bounding box is empty, false if it is not empty

  • (Boolean)

Version:

  • SketchUp 6.0

#heightObject

The height method is used to retrieve the height of the bounding box.

The height is returned in the currently set units (inches, by default).

Examples:

boundingbox = Geom::BoundingBox.new
boundingbox.add([100, 200, -400], [200, 400, 100])
# This will return a Length of 200.0.
length = boundingbox.height

Returns:

  • height - the height of the bounding box

Version:

  • SketchUp 6.0

#intersect(boundingbox) ⇒ Object

Note:

Prior to SU2015 this method would return incorrect result in some cases. For correct result in these versions you must first check if the boundingboxes actually overlap - then call this to get the resulting boundingbox.

The intersect method is used to retrieve a bounding box that is the result of intersecting one bounding box with another.

Examples:

boundingbox1 = Geom::BoundingBox.new
boundingbox1.add([100, 200, -400], [200, 400, 300])
boundingbox2 = Geom::BoundingBox.new
boundingbox2.add([150, 350, 100], [200, 400, 500])
# The returned boundingbox is a result of the intersection of the two.
boundingbox = boundingbox1.intersect(boundingbox2)

Returns boundingbox - the resulting BoundingBox object if successful, an empty BoundingBox object if unsuccessful.

Parameters:

  • boundingbox

    A second boundbox which might intersect boundingbox1.

Returns:

  • boundingbox - the resulting BoundingBox object if successful, an empty BoundingBox object if unsuccessful.

Version:

  • SketchUp 6.0

#maxObject

The max method is used to retrieve the Point3d object where x, y and z are maximum in the bounding box.

If you attempt to call the max method on an empty bounding box, you will receive a very large negative number.

Examples:

boundingbox = Geom::BoundingBox.new
boundingbox.add([100, 200, -400], [700, 900, 800], [200, 400, 100])
# This will return a point Point3d(700, 900, 800).
point = boundingbox.max

Returns:

  • point - a Point3d object representing the point where x, y, and z are the maximum in the bounding box.

Version:

  • SketchUp 6.0

#minObject

The min method is used to retrieve the Point3d where x, y and z are minimum in the bounding box.

Examples:

boundingbox = Geom::BoundingBox.new
boundingbox.add([100, 200, -400], [700, 900, 800], [200, 400, 100])
# This will return a point Point3d(100, 200, -400).
point = boundingbox.min

Returns:

  • point - a Point3d object representing the point where x, y, and z are the maximum in the bounding box.

Version:

  • SketchUp 6.0

#valid?Object

The valid method is used to determine if a bounding box is valid (contains points).

Examples:

boundingbox = Geom::BoundingBox.new
boundingbox.add([100, 200, -400], [200, 400, 100])
# This will return true.
boundingbox.valid?

Returns:

  • status - true if the bounding box is valid (not empty), false if it is not valid (empty)

  • (Boolean)

Version:

  • SketchUp 6.0

#widthObject

The width method is used to retrieve the width of the bounding box.

The width is returned in the currently set units (inches, by default).

Examples:

boundingbox = Geom::BoundingBox.new
boundingbox.add([100, 200, -400], [200, 400, 100])
# This will return a Length of 100.0.
length = boundingbox.width

Returns:

  • width - the width of the bounding box

Version:

  • SketchUp 6.0