point on face of solid

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
Torxal
Posts: 11
Joined: Wed May 11, 2022 8:51 pm

point on face of solid

Post by Torxal »

Hey everybody,

for a given FreeCAD.Vector i want to check if there is a face of a solid object nearby.

For example i create a box with the default edge length of 10 mm with:

Code: Select all

App.ActiveDocument.addObject("Part::Box","Box")
TheBox.PNG
TheBox.PNG (8.19 KiB) Viewed 789 times
Now i can create a Vector with:

Code: Select all

poi = FreeCAD.Vector(5,10,5) 
From using the GUI i know that poi should be on face4. So i get face 4 with:

Code: Select all

foi = App.ActiveDocument.Box.Shape.Faces[4]
TheBox2.PNG
TheBox2.PNG (12.69 KiB) Viewed 783 times
Now i want to check if poi is nearby/inside with tolerance foi.

So i call:

Code: Select all

 foi.isInside(poi,2.5,True)
The result is for every tolerance i set is:

False:

What can i do? I found this unsolved old post https://forum.freecadweb.org/viewtopic. ... =3&t=31524 with a similar problem.

Using:
FreeCAD 0.19
Windows 10
TheMarkster
Veteran
Posts: 5513
Joined: Thu Apr 05, 2018 1:53 am

Re: point on face of solid

Post by TheMarkster »

Faces[4] is not Face4, it's Face5 since Faces is 0-indexed.
Torxal
Posts: 11
Joined: Wed May 11, 2022 8:51 pm

Re: point on face of solid

Post by Torxal »

@TheMarkster thanks :D ! My fault :roll:. So i call face 5. But why i dont get a True for a big tolerance like 1000?
User avatar
Chris_G
Veteran
Posts: 2601
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: point on face of solid

Post by Chris_G »

Function isInside splits shapes in 2 groups :
- volumetric shapes are treated with BRepClass3d_SolidClassifier
- non-volumetric shapes are treated with BRepExtrema_DistShapeShape

I think there is a bug here, and Faces should be treated as non-volumetric, along with vertexes, edges and wires.
User avatar
onekk
Veteran
Posts: 6222
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: point on face of solid

Post by onekk »

Chris_G wrote: Tue Jul 19, 2022 8:57 pm I think there is a bug here, and Faces should be treated as non-volumetric, along with vertexes, edges and wires.
Maybe asking @wmayer could be a good idea?

From OCC documentation you linked about BRepExtrema_DistShapeShape:
This class provides tools to compute minimum distance between two Shapes (Compound,CompSolid, Solid, Shell, Face, Wire, Edge, Vertex).
So it could be used on these entities, but maybe there are or there were some problems with the class in some corner cases, and sadly if there are no comments, in the source code it is difficult to say something.

But as "wmayer committed on 23 Oct 2021" :

https://github.com/FreeCAD/FreeCAD/comm ... 2645605c13


It will be interesting to see what he has to say about this choice, at least to improve knowledge if internals, I'm saving most of the latest wmayer posts, as they are very interesting and almost always improve my personal knowledge about FC.

Sorry for bothering and not giving relevant information about the OT.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
wmayer
Founder
Posts: 20319
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: point on face of solid

Post by wmayer »

Yes, it's a bug and is fixed with git commit 639ff927de.
wmayer
Founder
Posts: 20319
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: point on face of solid

Post by wmayer »

I think an even better option is the class BRepClass_FaceClassifier because similar to BRepClass3d_SolidClassifier you can distinguish between a point is part of the inner of a face or on its boundary.

EDIT: No, it's not. It unexpectedly returns true for

Code: Select all

box.Face4.isInside(FreeCAD.Vector(5,11,5), 0.0, False)
or

Code: Select all

box.Face4.isInside(FreeCAD.Vector(5,9,5), 0.0, False)
Post Reply