[Code] intersect_with?() Group test method
-
*Author*::*SomeLib*.intersect_with?( grp1, grp2 [, precision] )Test whether two groups have a boolean intersection. Returns
true||false.( Method is non-destructive, and does not change either reference. )
module Author;;SomeLib class << self # PROXY CLASS #{ intersect_with?( grp1, grp2 [, precision] ) #{ # Test whether two groups have a boolean intersection. # # (Method is non-destructive, and does not change either reference.) # # grp1 ; a Sketchup;;Group or Sketchup;;ComponentInstance reference. # grp2 ; a Sketchup;;Group or Sketchup;;ComponentInstance reference. # precision ; number of decimal places for precision (default = 3.) # # Returns; true, if "grp1" intersects with "grp2" argument. # false, if they do not intersect. # nil, if either are not manifold, Sketchup is not Pro, # or if the groups are in different contexts. #} def intersect_with?( grp1, grp2, prec=3 ) #{ unless grp1.is_a?(Sketchup;;Group) || grp1.is_a?(Sketchup;;ComponentInstance) raise(TypeError,"(arg 0) Sketchup;;Group or Sketchup;;ComponentInstance expected.",caller) end unless grp2.is_a?(Sketchup;;Group) || grp2.is_a?(Sketchup;;ComponentInstance) raise(TypeError,"(arg 1) Sketchup;;Group or Sketchup;;ComponentInstance expected.",caller) end return nil unless Sketchup.is_pro? && Sketchup.version.to_i>7 return nil unless (grp1.manifold? && grp2.manifold?) return nil unless (grp1.model == grp2.model) return nil unless (grp1.parent == grp2.parent) #} tgrp = nil retval = false mdl = grp1.model vola = volb = grp1.volume.to_l # begin # mdl.start_operation('Intersect Test') ### # if grp1.is_a?(Sketchup;;Group) tgrp = grp1.copy else grp1.is_a?(Sketchup;;ComponentInstance) tgrp = grp1.parent.entities.add_instance(grp1.definition,grp1.transformation) end # vola = grp2.trim(tgrp).volume.to_l # ### mdl.commit_operation # rescue Exception => e mdl.abort_operation puts(e.message) puts(e.backtrace) return nil else # Sketchup.undo # if prec==3 return puts( vola == volb ? false ; true ) else aft = ((vola*(10**prec)).to_i)/((10**prec).to_f) bef = ((volb*(10**prec)).to_i)/((10**prec).to_f) return puts( aft == bef ? false ; true ) end end # end #} end # PROXY CLASS end # moduleTested OK with 2 cuboids that intersected at their corners by 0.001" x 0.001" x 0.001"

-
Hi,
May I know after determining if the 2 groups/ components/ faces are intersected. How do I get the area of the intersection?
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement