How do you intersect two faces?
-
I want to intersect two groups (
g0
,g1
) and put the intersection edges in a third group. Sinceintersect_with
is very slow on complex geometry it should pay to find pairs of faces fromg0
andg1
that might intersect and then intersect those pairs separately. An example, I have two groups with roughly 11000 faces each. This requires 121 million face/face comparisons, however, with some space hashing this number drops to ~400.000 from which ~4000 pairs of potential face intersections are extracted (ie. face pairs whose bounding boxes intersect). The whole procedure takes about a second. (To intersect the groups from the UI takes 16 minutes..)Now, is there a way in sketchup to intersect just two faces? I'm at loss on how to use
intersect_with
for this and the Geom class contains only plane/plane intersection. -
Join the party...
intersect_with is slow, but probably necessary evil.
That's quite a large collection you are having.
I found it ever so slightly faster in 2Dboolean to intersect with 1 of the groups containing edges only, to cut out the desired frame of desired geometry. But in your case that might not aid.
I reported a strange behavior from that that never got answered, or maybe it's so well known it did not deserve an answer.."Edge collection still remembers face" - error, sort of thing..(scroll to my post)
http://sketchucation.com/forums/viewtopic.php?f=180%26amp;t=55238%26amp;hilit=+intersectThere was some post long time ago about using linesweeps instead, in the Cartesian plane.
And perhaps break edges on "hit". I don't think it's trivial to build something like that..
Maybe if it could be ported to C doing the calculations, however the cost..TIG's many plugins use intersections quite often. You should dig in there..
If you would come up with something revolutionary you'd be a hero..
-
The heart of your problem is that intersect_with is an instance method of the Entities collection class. So, you need to create a temporary Entities collection and copy one of the Faces into it. For instance (assuming that the Faces are drawn in model coordinates - otherwise you will need to use something other than the identity Transformation):
temp_ents = Sketchup.active_model.entities.add_group.entities # can reuse this if purge between pairs of Faces temp_ents.add_face(face1.edges) ident = Geom;;Transformation.new intersect_arr = temp_ents.intersect_with(false, ident, temp_ents, ident, false, face2)
Because it is all Ruby, I don't know whether this will actually be any faster than letting the built-in function handle the whole thing though.
Steve
-
This is what I do (sort of) in 2dboolean. But with 11000 faces ...
@unknownuser said:
Because it is all Ruby, I don't know whether this will actually be any faster than letting the built-in function handle the whole thing though.
20 seconds is better than 25 every optimization counts or are worth trying
-
Thanks for the replies!
slbaumgartner, splendid advice. It worked much smoother than I thought it would. The code is attached below. Here are some results from intersecting the two columns in the example file:
-
Intersect from UI: 983s
-
Outer shell (*****): 161s
-
g0.intersect_with g1 (******): 104s
-
Intersect face pairs: 4s
() Outer shell is probably dominated by the intersect
(*) In order to produce all edges for coplanar cuts two calls tointersect_with
has to be made with the groups reversed. The result above is for a single call.
-
Advertisement