"collision detection", overlapping

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
teobo
Posts: 410
Joined: Fri Feb 21, 2014 11:23 am

"collision detection", overlapping

Post by teobo »

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
Veteran
Posts: 53933
Joined: Tue Mar 17, 2015 9:14 am

Re: "collision detection", overlapping

Post by chrisb »

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
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
mario52
Veteran
Posts: 4673
Joined: Wed May 16, 2012 2:13 pm

Re: "collision detection", overlapping

Post by mario52 »

Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
JMG
Posts: 287
Joined: Wed Dec 25, 2013 9:32 am
Location: Spain
Contact:

Re: "collision detection", overlapping

Post by JMG »

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
Veteran
Posts: 4673
Joined: Wed May 16, 2012 2:13 pm

Re: "collision detection", overlapping

Post by mario52 »

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, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
JMG
Posts: 287
Joined: Wed Dec 25, 2013 9:32 am
Location: Spain
Contact:

Re: "collision detection", overlapping

Post by JMG »

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
Veteran
Posts: 4673
Joined: Wed May 16, 2012 2:13 pm

Re: "collision detection", overlapping

Post by mario52 »

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, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
galou_breizh
Posts: 436
Joined: Wed Sep 15, 2010 9:38 am

Re: "collision detection", overlapping

Post by galou_breizh »

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
JMG
Posts: 287
Joined: Wed Dec 25, 2013 9:32 am
Location: Spain
Contact:

Re: "collision detection", overlapping

Post by JMG »

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

Post by teobo »

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?
Post Reply