BoundingBox.intersect
-
Has anyone had problems with this. This is my first time using it, and I'm using it in conjunction with valid? to see if there are any points.
What I've found is that if my two groups (in this case cubes) don't share any X-axis limits, then it correctly identifies if the objects touch or not. If however they have overlapping X-axis limits, it always returns "true" for BoundingBox.intersect.valid? even if the Y-axis and Z-axis limits don't overlap at all. If any of the three axes don't overlap the valid? should return "false" Below I took the code from the API sample and adjusted it to show two parallel lines that are running along the Y and then the X axis. They should both return false, but the pair along the X axis returns true.
Any thoughts on this?
http://code.google.com/intl/zh-CN/apis/sketchup/docs/ourdoc/boundingbox.html#intersect
boundingbox1 = Geom;;BoundingBox.new boundingbox1.add [0,0,0] boundingbox1.add [0,100,0] boundingbox2 = Geom;;BoundingBox.new boundingbox2.add [100,0,0] boundingbox2.add [100,100,0] boundingboxA = boundingbox1.intersect boundingbox2 puts boundingboxA.valid? boundingbox3 = Geom;;BoundingBox.new boundingbox3.add [0,0,0] boundingbox3.add [100,0,0] boundingbox4 = Geom;;BoundingBox.new boundingbox4.add [0,100,0] boundingbox4.add [100,100,0] boundingboxB = boundingbox3.intersect boundingbox4 puts boundingboxB.valid?
boundingboxA.valid? correctly returns "false"
boundingboxB.valid? incorrectly returns "true"FYI - I have attached a screenshots of a simple example using two cubes where one returns true and the other false. Code above is similar but just two lines, vs. two boxes.
![This correctly shows boundingbox.intersect? as "false"](/uploads/imported_attachments/EJqD_intersectreturnsfalse.png "This correctly shows boundingbox.intersect? as "false"")
![This incorrectly shows boundingbox.intersect? as "true"](/uploads/imported_attachments/psx5_intersectreturnstrue.png "This incorrectly shows boundingbox.intersect? as "true"")Just a short followup. If I add the following code to each pair of lines here are the results
puts boundingboxA.diagonal puts boundingboxA.height puts boundingboxA.depth puts boundingboxA.width puts boundingboxA.corner (0) puts boundingboxA.corner (1) puts boundingboxA.corner (2) puts boundingboxA.corner (3) puts boundingboxA.corner (4) puts boundingboxA.corner (5) puts boundingboxA.corner (6) puts boundingboxA.corner (7)
8' 4"
8' 4"
0"
0"
(1000000000000000000000000000000", 0", 0")
(-1000000000000000000000000000000", 0", 0")
(1000000000000000000000000000000", 100", 0")
(-1000000000000000000000000000000", 100", 0")
(1000000000000000000000000000000", 0", 0")
(-1000000000000000000000000000000", 0", 0")
(1000000000000000000000000000000", 100", 0")
(-1000000000000000000000000000000", 100", 0")
false
8' 4"
0"
0"
8' 4"
(1000000000000000000000000000000", 0", 0")
(100", 1000000000000000000000000000000", 0")
(0", -1000000000000000000000000000000", 0")
(100", -1000000000000000000000000000000", 0")
(0", 1000000000000000000000000000000", 0")
(100", 1000000000000000000000000000000", 0")
(0", -1000000000000000000000000000000", 0")
(100", -1000000000000000000000000000000", 0")
true
"" -
@unknownuser said:
(1000000000000000000000000000000", 0", 0")
Seems like a long way from home. I would have thought the bb to be around the ORIGIN.
I've never used the .intersect method - never realized it existed until now, actually.
-
I thought it was a long way from home as well. I thought it would be an empty bounding box without any points, so I didn't know what I expected corner 0 to return, I thought maybe "nil"
By the way, here is what I get for points on a new empty bounding box.
boundbox = Geom;;BoundingBox.new puts boundbox.height puts boundbox.width puts boundbox.depth puts boundbox.corner 0 puts boundbox.corner 1 puts boundbox.corner 2 puts boundbox.corner 3 puts boundbox.corner 4 puts boundbox.corner 5 puts boundbox.corner 6 puts boundbox.corner 7 boundbox.valid?
Height, Depth, and Width return 0 (instead of the 8'4" that came up on my earlier example), but still large number for point coordinates. The 8'4" is the 100 inches, but I don't know how that ever got to be the height in the earlier example.
0"
0"
0"
(1000000000000000000000000000000", 1000000000000000000000000000000", 1000000000000000000000000000000")
(-1000000000000000000000000000000", 1000000000000000000000000000000", 1000000000000000000000000000000")
(1000000000000000000000000000000", -1000000000000000000000000000000", 1000000000000000000000000000000")
(-1000000000000000000000000000000", -1000000000000000000000000000000", 1000000000000000000000000000000")
(1000000000000000000000000000000", 1000000000000000000000000000000", -1000000000000000000000000000000")
(-1000000000000000000000000000000", 1000000000000000000000000000000", -1000000000000000000000000000000")
(1000000000000000000000000000000", -1000000000000000000000000000000", -1000000000000000000000000000000")
(-1000000000000000000000000000000", -1000000000000000000000000000000", -1000000000000000000000000000000")
"false" -
I can only guess, but do the large numbers mean infinite overlap in that dimension because that dimension has 0 length? (Or something like that.)
-
Are you using SU6? I seem to remember the intersect is broken in SU6.
-
Nope, I'm using current version of 7.1 on PC, I haven't tried on my mac PC at home.
-
So if this is a bug here is my workaround may be to create similar results by using min and max points for the two bounding boxes being intersected. For my use I just need to know if they intersect, not what that resulting bounding box is.
This isn't code, just outline of what I'm thinking
Get min max for bounding box a and b
min a
max a
min b
max bif
min ax < min bx < max ax or min ax < max bx < max ax
and
min ay < min by < max ay or min ay < max by < max ay
and
min az < min bz < max az or min az < max bz < max azthen bounding boxes intersect
else
they don’t intersect -
I used bounding box intersection in my Slots 4 Tabs plugin. How about using volume to see if they intersect?
b1 = sel[0].bounds
b2 = sel[1].bounds
bb = b1.intersect b2
puts bb.valid?
puts bb.width * bb.height * bb.depth -
I see the same problem. It does seem like a clear bug. Align the boxes along each of the 3 axes, test for valid BB.intersect, and 2 of 3 alignments return valid, while the 3rd (along X) returns not valid.
-
I'm seeing the same problem, tested on both Mac and PC with SU 7.1.6
this is clearly a bug as the function does not do what it's name represents. although this would be renamed and used to find if 2 bounding boxes are within the same projected space.
I recently posted pretty much the same post here:
Advertisement