Global.bounds (is there a way to mimic this)
-
There doesn't seem to be a "global.bounds" method similar to "local.bounds". Is there a way to mimic this using transformation.
Here is what I'm trying to do. I have two faces in different groups. I want to see if their bounding boxes overlap using something like "bounds_a.contains? (bounds_b)".
I can find the transformation for the parent group for each face, but I can't apply that transformation to the bounding box. Below is a link to a post with some code showing how to transform a corner of the bounding box. I suppose I could do this for all 8 corners and then make a new bounding box, but I'm iterating through a lot of entities, and that may slow it down more than necessary. Any thoughts?
http://forums.sketchucation.com/viewtopic.php?f=180&t=25752&p=221660&hilit=transform+a+bounding+box#p221660my_comp = a_component t = my_comp.transformation comp_def = my_comp.definition def_t = comp_def.bounds.corner(0) new_t = t * def_t
Code came from Chris Fullmer's post in the thread
David
-
I'm trying to wrap my head around what you're trying to get at. Your two faces, you want their bounding boxes, yeah? Global ones, so the bounding box will not be aligned to the face, but to the world coordinates? If so, I tihnk that is what SketchUp will do by defrault. Make a new bounding box object, then add your face to it. And it should be globally oriented - I think. I'm not sure how it will re-act inside of a group I guess.
Does that start to get at what you need?
Chris
-
It seems within a group that it gives the bounds relative to the group origin vs. the global origin.
So if I test two faces each in different groups. If the faces do overlap, the test passes when the group origins are the same, but fails if the group origins are not the same.
If I want to find the bounding box for the group as as whole, then it seems I have the option to use bounds (for global) or local_bounds (for local), but I can't seem to apply that principle to objects within a group.
-
if you have the group to model transformation, you can create a new bounding box, then add the face's vertices to it.
something like this:(untested)
bbox = Geom;;BoundingBox.new points = face.vertices.collect{|vertex| vertex.position.transform(toModelTransformation)} points.each{|point| bbox.add(point)}
This will still give a bounding box larger than the face if you don't have the face perfectly aligned with the global axes, though.
-
thanks, I'll give that a try.
David
update:
Chris, thanks! that worked perfectly.
Advertisement