Not understanding face normals

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
sliptonic
Veteran
Posts: 3459
Joined: Tue Oct 25, 2011 10:46 pm
Location: Columbia, Missouri
Contact:

Not understanding face normals

Post by sliptonic »

I've run into (another) defect in my basic understanding of FreeCAD.
I created a body with just a simple padded rectangle. Put the body into a Part.
Then select the top face and get the normal.

Code: Select all

>>> face = App.getDocument("Unnamed").getObject("Pad").Shape.Face6
>>> u, v = face.ParameterRange[:2]
>>> face.normalAt(u,v)
Vector (-0.0, -0.0, 1.0)
Then rotate the part. and repeat the process. I still get exactly the same result.
How do I get the normal of the face in its current pose in the global coordinate system?
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Not understanding face normals

Post by openBrain »

sliptonic wrote: Wed Nov 17, 2021 5:08 pm How do I get the normal of the face in its current pose in the global coordinate system?
Multiply result by App.getDocument("Unnamed").getObject("Pad").getGlobalPlacement().Rotation ;)
Last edited by openBrain on Wed Nov 17, 2021 7:08 pm, edited 1 time in total.
wmayer
Founder
Posts: 20305
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Not understanding face normals

Post by wmayer »

sliptonic wrote: Wed Nov 17, 2021 5:08 pm Then rotate the part. and repeat the process. I still get exactly the same result.
This doesn't change the placement of the shape of the pad at all.
openBrain wrote: Wed Nov 17, 2021 5:15 pm Multiply result by App.getDocument("Unnamed").getObject("Pad").getGlobalPlacement() ;)
Be careful: This is not quite correct. Here the difference of a 3d point and a 3d vector will be relevant as the latter is position-invariant. And this has a consequence in how to compute the face normal of the rotated pad. From the placement you must use the rotation part only but ignore the translation part.

Code: Select all

pad = App.ActiveDocument.getObject("Pad")
face = pad.Shape.Face6

u, v = face.ParameterRange[:2]
n = face.normalAt(u,v)

plm = pad.getGlobalPlacement()
rot = plm.Rotation
rot.multVec(n)
According to your description you only rotate but do not move the Part so that in this special case it would work. But just for fun also move the Part object and then compare the results of

Code: Select all

rot.multVec(n)
plm.multVec(n)
and you will see the difference.
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Not understanding face normals

Post by openBrain »

wmayer wrote: Wed Nov 17, 2021 6:58 pm Be careful: This is not quite correct.
My mistake. Don't know why but I only partially copied the line. I corrected my previous post if someone else comes here. Thanks for vigilance.
User avatar
Roy_043
Veteran
Posts: 8547
Joined: Thu Dec 27, 2018 12:28 pm

Re: Not understanding face normals

Post by Roy_043 »

Thanks from me as well:
https://github.com/FreeCAD/FreeCAD/blob ... ne.py#L566
Still learning... :mrgreen:
Post Reply