Is Point on Face ?

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
cristian.a73
Posts: 41
Joined: Wed Jul 18, 2018 4:15 pm

Is Point on Face ?

Post by cristian.a73 »

Hi FreeCAD Forumer

I'm looking for and good and efficient answer to the subject question
In my first approach by using vertex.distToSHape(face) a good solution was found :

*** TEST distToShape | face_name:Face45 | dist:(2.595767256003112e-05, [(Vector (-22.0812, -11.1074, 16.2178), Vector (-22.08122421877031, -11.107390659125876, 16.2178))], [('Vertex', 0, None, 'Face', 0, (4.330483527529996, -9.762040895517398))]) :mrgreen:

The code work fine in Windows7.FreeCAD 0.17 ,,, but ,,, in Ubuntu.FreeCAD 0.18 the result is different :

*** TEST I distToShape | face_name:Face45 | dist:(3.1644938021069278, [(Vector (-22.0812, -11.1074, 16.2178), Vector (-23.2199680025423, -14.0598952938081, 16.2178))], [('Vertex', 0, None, 'Edge', 1, 9.762040895517398)]) :?:

May be shape.distToShape(shape) was changed ...


so the question is : is there a way to make distToShape return the entity 'Face' as the old implementation ?

... or is there a way to detect if a point is on face ?

Thank you
Cristian
User avatar
wandererfan
Veteran
Posts: 6326
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Is Point on Face ?

Post by wandererfan »

cristian.a73 wrote: Sat Oct 13, 2018 11:10 am ... or is there a way to detect if a point is on face ?
How about myFace.isInside(myPoint, tolerance, true)?

"isInside"
- Checks whether a point is inside or outside the shape. isInside(App.Vector, float, Boolean) => Boolean
The App.Vector is the point you want to check if it's inside or not
float gives the tolerance
Boolean indicates if the point lying directly on a face is considered to be inside or not
User avatar
cristian.a73
Posts: 41
Joined: Wed Jul 18, 2018 4:15 pm

Re: Is Point on Face ?

Post by cristian.a73 »

wandererfan wrote: Sat Oct 13, 2018 12:40 pm How about myFace.isInside(myPoint, tolerance, true)?

"isInside"
- Checks whether a point is inside or outside the shape. isInside(App.Vector, float, Boolean) => Boolean
The App.Vector is the point you want to check if it's inside or not
float gives the tolerance
Boolean indicates if the point lying directly on a face is considered to be inside or not
Thank you wandererfan for yout suggestion, it was my very first method...
... the proble is isInside doesn't work as apsected : see the log :

Code: Select all

>>> p2 = FreeCAD.Vector(112.216,115.785,10.7989)
>>> vx2 = Part.Vertex(p2)
>>> f.isInside(p2, 0.1, True)
False
>>> vx2.distToShape(f)
(0.00288570504590466, [(Vector (112.216, 115.785, 10.7989), Vector (112.21469374568731, 115.785, 10.79632687091607))], [('Vertex', 0, None, 'Face', 0, (0.7778714902086804, 143.14689910059903))])
By playing around it isInside(point, toll, bool) work fine on shape...but it does'nt answer to the subject question :
a point may be inside the shape, or on the shape's faces, but out of the target face
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Is Point on Face ?

Post by DeepSOIC »

cristian.a73 wrote: Sat Oct 13, 2018 1:07 pm point may be inside the shape, or on the shape's faces, but out of the target face
then, use f.Faces[index_of_your_target_face].isInside(…)
User avatar
cristian.a73
Posts: 41
Joined: Wed Jul 18, 2018 4:15 pm

Re: Is Point on Face ?

Post by cristian.a73 »

DeepSOIC wrote: Sat Oct 13, 2018 5:48 pm then, use f.Faces[index_of_your_target_face].isInside(…)
thank you but it doesn't work :

Code: Select all

>>> vx2.distToShape(f)
(0.00288570504590466, [(Vector (112.216, 115.785, 10.7989), Vector (112.21469374568731, 115.785, 10.79632687091607))], [('Vertex', 0, None, 'Face', 0, (0.7778714902086804, 143.14689910059903))])
>>> f.Faces[0].isInside(vx2.Point, 0.1, True)
False
>>> f.Faces
[<Face object at 14BF9488>]

Code: Select all

>>> vx2.distToShape(obj.Shape.Faces[3])
(0.00288570504590466, [(Vector (112.216, 115.785, 10.7989), Vector (112.21469374568731, 115.785, 10.79632687091607))], [('Vertex', 0, None, 'Face', 0, (0.7778714902086804, 143.14689910059903))])
>>> obj.Shape.Faces[3].isInside(vx2.Point, 0.1, True)
False
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Is Point on Face ?

Post by DeepSOIC »

cristian.a73 wrote: Sat Oct 13, 2018 5:58 pm thank you but it doesn't work :
I tried, and it appeared to work. But then I tried checking if it respects tolerance, and it looks like it doesn't.

My face lies on XY plane, and covers the origin. I tried raising the point (increase Z). And only if Z is < 1e-12, it returned True. Both argument tolerance and shape tolerance are ignored. 1e-12 is a value known as Presicion::Angular in opencascade, btw.
User avatar
cristian.a73
Posts: 41
Joined: Wed Jul 18, 2018 4:15 pm

Re: Is Point on Face ?

Post by cristian.a73 »

DeepSOIC wrote: Sat Oct 13, 2018 6:57 pm I tried, and it appeared to work. But then I tried checking if it respects tolerance, and it looks like it doesn't.

My face lies on XY plane, and covers the origin. I tried raising the point (increase Z). And only if Z is < 1e-12, it returned True. Both argument tolerance and shape tolerance are ignored. 1e-12 is a value known as Presicion::Angular in opencascade, btw.
May be different implementation give discontinuous results...i've tested it on windows 0.17 and ubuntu 0.18 on a bspline surface
Post Reply