"collision detection", overlapping

Need help, or want to share a macro? Post here!
User avatar
teobo
Posts: 410
Joined: Fri Feb 21, 2014 11:23 am

"collision detection", overlapping

Postby teobo » Thu Sep 10, 2015 6:19 am

Hi,
just for curiosity: Once someone showed off about "collision detection" in his CAD. Since then ;) I wondered is there is a way in freecad, to say, finding out if two shapes are overlapping?
Maybe there is a (FreeCAD or occ) function near it?
And one might ask, how important would be such "overlapping detection" for an cad-program. Opinions?
Tia
chrisb
Posts: 22445
Joined: Tue Mar 17, 2015 9:14 am

Re: "collision detection", overlapping

Postby chrisb » Thu Sep 10, 2015 7:53 am

It should be easy, at least in python: Make an intersection and get the volume, this macro could help: http://freecadweb.org/wiki/index.php?title=Macro_FCInfo
mario52
Posts: 2857
Joined: Wed May 16, 2012 2:13 pm

Re: "collision detection", overlapping

Postby mario52 » Thu Sep 10, 2015 8:57 am

Maybe you need a special feature, go into Macros_recipes and Code_snippets, Dialog creation. My macros on Gist.github.
User avatar
JMG
Posts: 278
Joined: Wed Dec 25, 2013 9:32 am
Location: Spain
Contact:

Re: "collision detection", overlapping

Postby JMG » Thu Sep 10, 2015 9:20 am

Hi!

I've written this brief script that looks for common volumes between shapes and colors them in red:
Select the shapes and copy-paste it, thats all. :)

Code: Select all

# JMG 2015
object_list = []
for obj in FreeCAD.Gui.Selection.getSelectionEx():
  obj = obj.Object
  object_list.append( obj )

for n in range( len(object_list) ):
  object_A = object_list[n]
  for i in range( len(object_list) ):
    if i <= n:
      pass
    
    else:
      object_B = object_list[i]
      common = object_A.Shape.common( object_B.Shape )
      if common.Volume > 0.0:
        FreeCAD.Console.PrintMessage( '-Intersection- ' + object_A.Name + ' with ' + object_B.Name + '\n')
        FreeCAD.Console.PrintMessage( 'Common volume' + str( common.Volume ) + '\n' + '\n' )
        
        intersection_object = FreeCAD.ActiveDocument.addObject( 'Part::Feature' )
        intersection_object.Shape = common
        intersection_object.ViewObject.ShapeColor = ( 1.0,0.0,0.0,1.0 )
        object_A.ViewObject.Transparency = 80
        object_B.ViewObject.Transparency = 80
Resut:
Image
FreeCAD scripts, animations, experiments and more: http://linuxforanengineer.blogspot.com.es/
Open source CNC hot wire cutter project (NiCr): https://github.com/JMG1/NiCr
Exploded Assembly Workbench: https://github.com/JMG1/ExplodedAssembly
mario52
Posts: 2857
Joined: Wed May 16, 2012 2:13 pm

Re: "collision detection", overlapping

Postby mario52 » Thu Sep 10, 2015 9:38 am

hi JMG
if you put your macros (this macro and Text sticker) in "Macros_recipes" they will be more easily accessible
you can request a write permission for the wiki or ask someone to do

mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Dialog creation. My macros on Gist.github.
User avatar
JMG
Posts: 278
Joined: Wed Dec 25, 2013 9:32 am
Location: Spain
Contact:

Re: "collision detection", overlapping

Postby JMG » Fri Sep 11, 2015 10:45 am

Code: Select all

if you put your macros (this macro and Text sticker) in "Macros_recipes" they will be more easily accessible
you can request a write permission for the wiki or ask someone to do
Thanks mario, I will ask for it, but I've never touched a wiki before (time to learn!) :)
FreeCAD scripts, animations, experiments and more: http://linuxforanengineer.blogspot.com.es/
Open source CNC hot wire cutter project (NiCr): https://github.com/JMG1/NiCr
Exploded Assembly Workbench: https://github.com/JMG1/ExplodedAssembly
mario52
Posts: 2857
Joined: Wed May 16, 2012 2:13 pm

Re: "collision detection", overlapping

Postby mario52 » Fri Sep 11, 2015 8:33 pm

hi
it's easier than Python, if you prefer to have visits to your site,
create a page with explanations and one link to download the code on your site
here for permission here Macros_recipes for the table of contents full macros
and ... here for the help ...
mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Dialog creation. My macros on Gist.github.
galou_breizh
Posts: 312
Joined: Wed Sep 15, 2010 9:38 am

Re: "collision detection", overlapping

Postby galou_breizh » Thu Sep 24, 2015 12:18 pm

Added (@JMG, I hope with your permission) as http://www.freecadweb.org/wiki/index.ph ... ightCommon.

Similarly, also added http://www.freecadweb.org/wiki/index.ph ... Difference.

Cheers,
Gaël
User avatar
JMG
Posts: 278
Joined: Wed Dec 25, 2013 9:32 am
Location: Spain
Contact:

Re: "collision detection", overlapping

Postby JMG » Thu Sep 24, 2015 8:57 pm

Added (@JMG, I hope with your permission) as
Sure, I had this in my TODO list, thanks for doing it :)
FreeCAD scripts, animations, experiments and more: http://linuxforanengineer.blogspot.com.es/
Open source CNC hot wire cutter project (NiCr): https://github.com/JMG1/NiCr
Exploded Assembly Workbench: https://github.com/JMG1/ExplodedAssembly
User avatar
teobo
Posts: 410
Joined: Fri Feb 21, 2014 11:23 am

Re: "collision detection", overlapping

Postby teobo » Tue Oct 13, 2015 9:07 pm

Thanks to all.
aha.
-disttoshape
-common (boolean intersection)
-and another interface in development

well, is it in use, maybe at simulating assemblies, when one piece hits the other, I ask myself? Are there examples for it?