类: Geom::BoundingBox


继承自:Object


概述


注意:对于面向相机的组件,bounding box返回其实际模型坐标范围的中心点。 但在7.0以及更早版本的sketchup中,.bounds方法则会返回其当时可见的坐标范围的中心点。

一个BoundingBox类表示一个与坐标轴方向对齐的三维长方体,其大小恰好将模型中的实体包含于其中。

所有的新模型都有一个包含其中所有实体的BoundingBox(含所有组和组件)。

另外,所有Drawingelement对象(绘图对象),包括组和组件都有BoundingBox。

BoundingBox的大小仅仅恰好包裹住模型或者组亦或组件中的所有实体。

你也可以调用BoundingBox.new方法来创建一个空的BoundingBox对象。

示例代码:

  1. # You can get the bounding box on a model.
  2. model = Sketchup.active_model
  3. model_bb = model.bounds
  4. # Or you can get the bounding box on any Drawingelement object.
  5. first_entity = model.entities[0]
  6. first_entity_bb = first_entity.bounds
  7. # Or you can create an empty bounding box of your own.
  8. boundingbox = Geom::BoundingBox.new

软件版本:

  • SketchUp 6.0

实例方法目录


add(*args) ⇒ Geom::BoundingBox

用于将点、顶点或者其他BoundingBox的坐标添加到现有的BoundingBox范围。

center ⇒ Geom::Point3d

用于提取BoundingBox的中心点。

clear ⇒ Geom::BoundingBox

用于清理一个BoundingBox。

contains?(point_or_bb) ⇒ Boolean

用于判定BoundingBox是否包含特定的点或者另一个BoundingBox对象。

corner(corner_index) ⇒ Geom::Point3d

用于获取BoundingBox对象的特定角点。

depth ⇒ Length

用于获取BoundingBox对象的z坐标范围大小。

diagonal ⇒ Length

用于获取BoundingBox对象的对角线长度大小。

empty? ⇒ Boolean

用于判定BoundingBox对象是否为空。

height ⇒ Length

用于获取BoundingBox对象的y坐标范围大小。

initialize ⇒ Geom::BoundingBox

用于创建一个空BoudingBox对象。

intersect(boundingbox) ⇒ Geom::BoundingBox

用于获取一个BoundingBox与另一个BoundingBox的交集。

max ⇒ Geom::Point3d

用于获取BoundingBox内三维坐标最大的点。

min ⇒ Geom::Point3d

用于获取BoundingBox内三维坐标最小的点。

valid? ⇒ Boolean

用于判定BoundingBox是否非空。

width ⇒ Length

用于获取BoundingBox对象的X坐标范围大小。


构造细节


initialize方法

  1. initialize Geom::BoundingBox

用于创建一个新的空BoundingBox对象。

示例代码:

  1. boundingbox = Geom::BoundingBox.new

软件版本:

  • SketchUp 6.0

实例方法细节


add方法

  1. add(point_or_bb) Geom::BoundingBox
  2. add(points_or_bb) Geom::BoundingBox

用于将点、顶点或者其他BoundingBox的坐标添加到现有的BoundingBox范围。

BoundingBox的大小会扩展至刚好包裹住新加入的元素。

向空BoundingBox对象添加一个点不会增加其大小。

要将BoundingBox的大小扩展到大于零,你必须向其中添加至少两个点。

示例代码:

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

重载:

add(point_or_bb) ⇒ Geom::BoundingBox

参数:
  • point_or_bb (Geom::Point3d, Geom::BoundingBox, Sketchup::Vertex)

add(points_or_bb) ⇒ Geom::BoundingBox

参数:
  • points_or_bb (Array)

返回值:

  • (Geom::BoundingBox)

软件版本:

  • SketchUp 6.0

center方法

center ⇒ Geom::Point3d

用于获取BoundingBox对象的中心点。

示例代码:

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

返回值:

  • (Geom::Point3d) — BoundingBox对象的中心点。

软件版本:

  • SketchUp 6.0

clear方法

  1. clear Geom::BoundingBox

用于清空一个BoundingBox对象。

清空后的BoundingBox对象大小不大于零。

示例代码:

  1. boundingbox = Geom::BoundingBox.new
  2. boundingbox.add([100, 200, -400], [200, 400, 100])
  3. # This will return false.
  4. boundingbox.empty?
  5. boundingbox.clear
  6. # This will return true.
  7. boundingbox.empty?

返回值:

  • (Geom::BoundingBox) — 清空后的BoundingBox对象。

软件版本:

  • SketchUp 6.0

contains?方法

  1. contains(point_or_bb) Boolean

用于判定BoundingBox对象是否包含特定的点或者另一个BoundingBox对象。

示例代码:

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

参数:

  • point_or_bb (Geom::Point3d,Geom::BoundingBox)

返回值:

  • (Boolean)

软件版本:

  • SketchUp 6.0

corner方法

  1. corner(corner_index) Geom::Point3d

用于获取BoundingBox对象的特定角点。

BoundingBox对象的八个角点以0-7的数字编码表示。

角点会以当时设定的单位返回(默认情况下为英尺)。

以下是角点编号的含义:

  1. - 0 = [0, 0, 0] 左前下(left front bottom)
  2. - 1 = [1, 0, 0] 右前下(right front bottom)
  3. - 2 = [0, 1, 0] 左后下(left back bottom)
  4. - 3 = [1, 1, 0] 右后下(right back bottom)
  5. - 4 = [0, 0, 1] 左前上(left front top)
  6. - 5 = [1, 0, 1] 右前上(right front top)
  7. - 6 = [0, 1, 1] 左后上(left back top)
  8. - 7 = [1, 1, 1] 右后上(right back top)

示例代码:

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

参数:

  • corner_index (Integer) — 表示角点位置的编码数字(0-7).

返回值:

  • (Geom::Point3d) — 如果成功运行返回一个Point3d对象。

软件版本:

  • SketchUp 6.0

depth方法

  1. depth Length

注意:在SketchUp坐标系统中,这个方法的返回值代表了高度。

用于获取BoundingBox对象的z坐标范围。

示例代码:

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

返回值:

  • (Length)

软件版本:

  • SketchUp 6.0

diagonal方法

  1. diagonal Length

用于获取BoundingBox对象的对角线长度。

示例代码:

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

返回值:

  • (Length) — BoundingBox对象的对角线长度。

软件版本:

  • SketchUp 6.0

empty?方法

  1. empty? Boolean

用于判定一个BoundingBox对象是否是空的。
返回值与valid?方法的返回值含义正好相反。

示例代码:

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

返回值:

  • (Boolean)

软件版本:

  • SketchUp 6.0

height方法

  1. height Length

注意:SketchUp坐标系统中,这个方法的返回值代表深度。

用于获取BoudingBox的Y坐标范围大小。

示例代码:

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

返回值:

  • (Length)

软件版本:

  • SketchUp 6.0

intersect方法

  1. intersect(boundingbox) Geom::BoundingBox

注意:SU2015及以前的软件版本中该方法会在某些情况下返回错误的结果。 这些情况下你必须首先检查BoundingBox对象是否确实重叠。

用于计算两个BoundingBox对象的交集。

示例代码:

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

参数:

  • boundingbox (Geom::BoundingBox) — 与已知的BoundingBox对象相交的第二个BoundingBox对象。

返回值:

  • (Geom::BoundingBox) — 运行成功时返回结果BoundingBox对象,不成功时返回一个空的BoundingBox对象。

软件版本:

  • SketchUp 6.0

max方法

  1. max Geom::Point3d

用于获取BoundingBox范围内三维坐标值均为最大处的点对象。

如果你将这个方法应用于一个空的BoundingBox对象,你会获得一个非常大的负数值。

示例代码:

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

返回值:

  • (Geom::Point3d) — BoundingBox范围内三维坐标值均为最大处的点对象。

软件版本:

  • SketchUp 6.0

min方法

  1. min Geom::Point3d

用于获取BoundingBox范围内三维坐标值均为最小处的点对象。

示例代码:

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

返回值:

  • (Geom::Point3d) — 表示BoundingBox范围内三维坐标最小值的点。

软件版本:

  • SketchUp 6.0

valid?方法

  1. valid? Boolean

用于判定BoundingBox是否是非空的。

示例代码:

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

返回值:

  • (Boolean)

软件版本:

  • SketchUp 6.0

width方法

  1. width Length

用于获取BoundingBox对象的x坐标范围。

示例代码:

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

返回值:

  • Length

软件版本:

  • SketchUp 6.0