Freecad collision detection

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
seanx
Posts: 33
Joined: Mon Nov 28, 2016 5:21 pm

Freecad collision detection

Post by seanx »

I am designing a 4 bar linkage mechanism.
I want to simulate the movement, and want to find out if they work as i intend them to.

I see in this video, that there is no collision detection in FreeCAD. https://www.youtube.com/watch?v=gV7jK0c7m40

So I google, and I find this. : https://www.youtube.com/watch?v=6CIorZvubtc

But this is using bounding boxes.

I want to do a proper collision detection, and take into account that some parts have non-parallelopoid shapes.

Is there any way to achieve it?

Thank you.
My projects, among others:

https://linktr.ee/siderealNight
User avatar
kwahoo
Posts: 680
Joined: Fri Nov 29, 2013 3:09 pm
Contact:

Re: Freecad collision detection

Post by kwahoo »

seanx wrote: Thu Dec 02, 2021 3:12 pm I want to simulate the movement
You can do this:
a) using Sketcher if the linkage is 2D
b) using Assembly3 if the linkage is 3D
c) using MBDyn addon if you have to take dynamics (masses, inertia moments) into account

I do not really understand why you need collision detection for 4 bar linkage, can you elaborate a bit more?
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: Freecad collision detection

Post by TheMarkster »

You could try taking the common of the 2 objects and checking it for volume as a means of collision detection. but this is likely to be painfully show.

Another option, make a Points object from one of the shapes in Points workbench, setting the tolerance fairly high so not many points are created. The more points you use the higher the precision and fewer intersections to be missed, but the longer processing time. With a setting of 2 for the tolerance I get 52 points from a default cylinder.
Snip macro screenshot-09ba05.png
Snip macro screenshot-09ba05.png (31.66 KiB) Viewed 3374 times
The points list can be accessed as obj.Points.Points in python. Let's call the other object obj2. We can get its shape property as obj2.Shape.

Code: Select all

contacted = [p for p in obj.Points.Points if obj2.Shape.isInside(p,.01,True)] #True means count points on face as intersecting
count = len(contacted)
print(f"There were {count} points of contact")
A default cylinder and default cube:
Snip macro screenshot-3291c9.png
Snip macro screenshot-3291c9.png (29.03 KiB) Viewed 3374 times
Intersecting points found using this method:
Snip macro screenshot-4b5b8e.png
Snip macro screenshot-4b5b8e.png (4.85 KiB) Viewed 3374 times
Snip macro screenshot-25ca5f.png
Snip macro screenshot-25ca5f.png (35.57 KiB) Viewed 3374 times
User avatar
bambuko
Veteran
Posts: 2165
Joined: Thu Oct 24, 2019 12:53 pm
Location: UK, England, North Devon

Re: Freecad collision detection

Post by bambuko »

kwahoo wrote: Thu Dec 02, 2021 3:30 pm ...You can do this:
b) using Assembly3 if the linkage is 3D
Like so, for example? (using Assembly 3)
Image
I am using Link branch and Assembly3
you can also download ... and try it here
excellent Assembly3 tutorials here
chrisb
Veteran
Posts: 53930
Joined: Tue Mar 17, 2015 9:14 am

Re: Freecad collision detection

Post by chrisb »

bambuko wrote: Thu Dec 02, 2021 8:18 pm Like so, for example? (using Assembly 3)
How did you create the smooth gif? I have created an animated gif by exporting a set of single frames and used Gimp to create the animation. But the result is rather clumsy.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
bambuko
Veteran
Posts: 2165
Joined: Thu Oct 24, 2019 12:53 pm
Location: UK, England, North Devon

Re: Freecad collision detection

Post by bambuko »

chrisb wrote: Fri Dec 03, 2021 1:45 am...How did you create the smooth gif? I have created an animated gif by exporting a set of single frames and used Gimp to create the animation. But the result is rather clumsy.
Most amusing :mrgreen:
I searched the forum how to do it and found your post describing using Gimp for it ;)
The difference lies (I am guessing) in a way I create single frames?
Model animation is controlled using dd and Assembly 3 - this allows me to create a set of precisely stepped (in this case every 10 deg) frames each screen grabbed in a fixed window. I had 36 frames for this gif.
I am using Link branch and Assembly3
you can also download ... and try it here
excellent Assembly3 tutorials here
chrisb
Veteran
Posts: 53930
Joined: Tue Mar 17, 2015 9:14 am

Re: Freecad collision detection

Post by chrisb »

Thanks, perhaps I should retry. Besides: it was my first FreeCAD project, so bare with me.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
bambuko
Veteran
Posts: 2165
Joined: Thu Oct 24, 2019 12:53 pm
Location: UK, England, North Devon

Re: Freecad collision detection

Post by bambuko »

chrisb wrote: Fri Dec 03, 2021 8:23 am ... it was my first FreeCAD project, so bare with me.
My first attempt at gif creation was decidedly crappy indeed :lol:
until I found your post that inspired me to try single frames and gimp (thank you for that!).
I am using Link branch and Assembly3
you can also download ... and try it here
excellent Assembly3 tutorials here
User avatar
kwahoo
Posts: 680
Joined: Fri Nov 29, 2013 3:09 pm
Contact:

Re: Freecad collision detection

Post by kwahoo »

chrisb wrote: Fri Dec 03, 2021 1:45 am How did you create the smooth gif? I have created an animated gif by exporting a set of single frames and used Gimp to create the animation. But the result is rather clumsy.
Btw
If this can be useful for anyone, I did this animation using A3, spreadsheet and writing a simple script and then encoding pics with ffmpeg.
chrisb
Veteran
Posts: 53930
Joined: Tue Mar 17, 2015 9:14 am

Re: Freecad collision detection

Post by chrisb »

Looks indeed very good. Can you provide the ffmpeg parameters?
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
Post Reply