BoundindBox intersect problem
-
I do think I've seen threads on the topic.
This appear to be a similar issue:
http://forums.sketchucation.com/viewtopic.php?f=180&t=28709 -
Thanks TT,
I wonder why I didn't see this topic, incorrect search keywords maybe... -
I used google instead of the forum search. Often does a better job.
-
@didier bur said:
I have to detect if 2 component instances (or their bounding boxes) of buildings intersect.
Are the building components manifold solids ??
If so you can use my
intersect_with?()
method, as is:
[ Code ] intersect_with?() Group test methodIf not, perhaps you can create two temporary manifold solids (using the bounding box vertices of the components,) then feed my
intersect_with?()
method, those temporary solids. After you get the boolean result, you can undo the operation (that created the temporary solids,) or just abort the operation. -
Thanks Dan,
The components are manifold solids.
I'll check your intersect_with? method asap and let you know. -
You could also use this - it doesn't need manifold solids...
tr=Geom::Transformation.new() tgp=entities.add_group() inst=obj1.entities.intersect_with(true,tr,tgp.entities,tr,false,obj2) tgp.erase! return true if inst[0] return nil
You might need to mess around with the 'transformations' if the 2 objects aren't in the same context ? -
Hmmm.. the API doctionary says that
entities.intersect_with()
returnsnil
Does it really return the new intersect edges ?? New faces ??
And if the objects are NOT in the same context.. would this method even intersect ?
-
@dan rathbun said:
Hmmm.. the API doctionary says that
entities.intersect_with()
returnsnil
Does it really return the new intersect edges ?? New faces ??
And if the objects are NOT in the same context.. would this method even intersect ?
The API is [as ever!] completely wrong - the method returns an array of all of the intersected results [edges typically, when put into a separate container as here] - just try it and see...
If the two intersecting objects are in different contexts you must adjust the transformations to reflect this - it can be done - I do it in 'Honeycomber'... -
IT's so crazy.. I never noticed the
Entities.intersect_with()
method before.At first blush, it seems a strange place to have it as an instance method of the
Entities
collection, (being why I did not notice it,) but when you think about it.. that's the correct place for it, so that the model's context can benefit as well. (The alternative would have been to define it 3 times, inModel
,Group
andComponent
.)I did notice a weird thing. If the groups do not intersect.. the temporary group is empty, and sometimes Sketchup deletes it. I did not expect this. I was trying to reuse the empty group reference for another intersect.. and got the ol' "reference to Deleted Entity" error.
I can see advantages to using this method rather than a boolean trim, as no undo would be needed. ( and might be faster.)
-
An empty temporary group will not survive long if you do other things, so create it just before you use it...
-
Hi guys,
Thanks for all these comments.
What I'have done finally is the following:- Made a hash with all my buildings and their local bounding boxes,
- Iterated through this hash and test all other bounding box points of other buildings,
- skiped all bounding boxes that are way too far to intersect with the considered building,
- coded a method to test if a 3dPoint is in a set of 8 points (a bounding box).
This is a very fast and efficient process (about 200 buildings collisions (with all 199 others) tested in 0.5 second)
Regards,
Advertisement