Find angle between adjacent faces

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
sliptonic
Veteran
Posts: 3457
Joined: Tue Oct 25, 2011 10:46 pm
Location: Columbia, Missouri
Contact:

Re: Find angle between adjacent faces

Post by sliptonic »

Brilliant! Works perfectly.
Nicely written too. It's easy for a guy with weak math skillz like mine to follow. Thanks for that!
xc22143
Posts: 139
Joined: Fri Dec 03, 2021 9:52 am

Re: Find angle between adjacent faces

Post by xc22143 »

wmayer wrote: Mon May 16, 2022 8:24 pm With the angle alone you cannot distinguish between the two cases. As already mentioned you have to distinguish between a convex area (face 1+2) and a concave area (face 2+3).

Now all what you need is e.g. a point that lies on one face but not on the adjacent face, i.e. the point must not be part of the common edge. Compute the distance of this point with the adjacent face.

If the distance is negative you have the convex case like face 1+2.
If the distance is positive you have the concave case like face 2+3.
If the distance is zero the two planes are co-planar.
How to define negative/positive and compute the distance of this point with the adjacent face? Is there any API in the python console?
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Find angle between adjacent faces

Post by wmayer »

A plane is defined by a base point and a normal vector.

Example:

Code: Select all

point = App.Vector(4,6,7) # this is the point to check

base = App.Vector(1,0,1) # this is the base of the plane
normal = App.Vector(1,1,1) # this is the normal of the plane

# the distance of the point to the plane can be obtained with
point.distanceToPlane(base, normal)
xc22143
Posts: 139
Joined: Fri Dec 03, 2021 9:52 am

Re: Find angle between adjacent faces

Post by xc22143 »

wmayer wrote: Mon Oct 10, 2022 1:14 pm A plane is defined by a base point and a normal vector.

Example:

Code: Select all

point = App.Vector(4,6,7) # this is the point to check

base = App.Vector(1,0,1) # this is the base of the plane
normal = App.Vector(1,1,1) # this is the normal of the plane

# the distance of the point to the plane can be obtained with
point.distanceToPlane(base, normal)
Thank you! that is great for the plane. It seems that it is not ok for the cylinder face or others.
User avatar
onekk
Veteran
Posts: 6144
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Find angle between adjacent faces

Post by onekk »

xc22143 wrote: Mon Oct 10, 2022 1:28 pm Thank you! that is great for the plane. It seems that it is not ok for the cylinder face or others.

It depends, you have to test.

Take in account that cylinder faces are 3, one (the side of the cylinder) is bended around the top and bottom face, so probably the chosen shape is the most problematic.

Probably for a cube it is different and more predictable.

Hope it helps

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: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Find angle between adjacent faces

Post by wmayer »

Thank you! that is great for the plane. It seems that it is not ok for the cylinder face or others.
This topic specifically is about planar faces. To test for infinite cylinder you can compute the distance to the cylinder axis. If it's lower than the radius the point is inside the cylinder, if it's equal to the radius the point is on the cylinder and if it's higher then the point is outside.
Post Reply