[ Solved ] Normal of a Sketch - Calculate Normal from Placement ?

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
paullee
Veteran
Posts: 5134
Joined: Wed May 04, 2016 3:58 pm

[ Solved ] Normal of a Sketch - Calculate Normal from Placement ?

Post by paullee »

Hi, it seems i am not familiar / confused by those geometrical terms.

Assume a Sketch map on XY plane (regardless of its content) has a Normal (0,0,1) correct?
(Map on XZ plane has a Normal (0,-1,0) )

Try to 'calculate' this Normal, (from the sketch's placement?), searching googling but find no previous discussion.

Any idea? Thanks.
Last edited by paullee on Mon Sep 16, 2019 2:40 pm, edited 1 time in total.
User avatar
Chris_G
Veteran
Posts: 2601
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Normal of a Sketch - Calculate Normal from Placement ?

Post by Chris_G »

I would do :

Code: Select all

normal = sketch.Placement.Rotation.multVec(FreeCAD.Vector(0,0,1))
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Normal of a Sketch - Calculate Normal from Placement ?

Post by openBrain »

Chris_G wrote: Sat Sep 14, 2019 8:48 pm I would do :

Code: Select all

normal = sketch.Placement.Rotation.multVec(FreeCAD.Vector(0,0,1))
This is perfect to get the normal vector in the LCS. :+1:
If normal vector in the GCS is needed, just change to :

Code: Select all

normal = sketch.getGlobalPlacement().Rotation.multVec(FreeCAD.Vector(0,0,1))
paullee
Veteran
Posts: 5134
Joined: Wed May 04, 2016 3:58 pm

Re: Normal of a Sketch - Calculate Normal from Placement ?

Post by paullee »

Thanks both for the solutions!
openBrain wrote: Sat Sep 14, 2019 9:12 pm If normal vector in the GCS is needed, just change to :

Code: Select all

normal = sketch.getGlobalPlacement().Rotation.multVec(FreeCAD.Vector(0,0,1))
Do some exercise, haven't figured out the difference between sketch.Placement and sketch.getGlobalPlacement() :-
  1. Make 2 Sketches
    (1st rectangle, 2nd triangle)
  2. Map the 2nd to 1st with ObjectXY mapmode
  3. Attachment Offset 0,0,50
  4. With 1st Sketch Placement at 0,0,0, 2nd's Placement / getGlobalPlacement are (0,0,50), so far so good.

Code: Select all

>>> s1.Placement
Placement [Pos=(0,0,0), Yaw-Pitch-Roll=(0,0,0)]
>>> s2.Placement
Placement [Pos=(0,0,50), Yaw-Pitch-Roll=(0,0,0)]
>>> s2.getGlobalPlacement()
Placement [Pos=(0,0,50), Yaw-Pitch-Roll=(0,0,0)]
  1. Now set 1st Sketch placement to (10,10,10), 2nd sketch move altogether, ok
  2. 2nd's Placement / getGlobalPlacement both return (10,10,60) ...

Code: Select all

>>> s2.Placement
Placement [Pos=(10,10,60), Yaw-Pitch-Roll=(0,0,0)]
>>> s2.getGlobalPlacement()
Placement [Pos=(10,10,60), Yaw-Pitch-Roll=(0,0,0)]
... I do not understand the correct way to use it ?


Screenshot from 2019-09-15 09-58-04.png
Screenshot from 2019-09-15 09-58-04.png (227.76 KiB) Viewed 680 times
Screenshot from 2019-09-15 10-09-29.png
Screenshot from 2019-09-15 10-09-29.png (195.41 KiB) Viewed 680 times
Attachments
Test_ Sketch_ Global Placement.FCStd
(4.68 KiB) Downloaded 18 times
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Normal of a Sketch - Calculate Normal from Placement ?

Post by openBrain »

paullee wrote: Sun Sep 15, 2019 2:17 am ... I do not understand the correct way to use it ?
Quite simple when you know. :lol:
'Attachment' properties in PartDesign are directly injected in 'Placement', thus changing them makes no difference as it doesn't rely in a LCS. ;)

To demonstrate, you have to use a 'container' that has an LCS, such as Body in the below example (also works with Part container).
In the attached file, 'Sketch' is mapped on XY plane with no offset/rotation.
However I changed the 'Body' Placement to offset 10,10,10 and rotation of 90° around X.
And now we see a difference. :P

Code: Select all

>>> App.ActiveDocument.Sketch.Placement
Placement [Pos=(0,0,0), Yaw-Pitch-Roll=(0,0,0)]
>>> App.ActiveDocument.Sketch.getGlobalPlacement()
Placement [Pos=(10,10,10), Yaw-Pitch-Roll=(0,0,90)]
Attachments
GGP.FCStd
(5.58 KiB) Downloaded 26 times
paullee
Veteran
Posts: 5134
Joined: Wed May 04, 2016 3:58 pm

Re: Normal of a Sketch - Calculate Normal from Placement ?

Post by paullee »

openBrain wrote: Sun Sep 15, 2019 8:29 am
Quite simple when you know. :lol:
'Attachment' properties in PartDesign are directly injected in 'Placement', thus changing them makes no difference as it doesn't rely in a LCS. ;)

To demonstrate, you have to use a 'container' that has an LCS, such as Body in the below example (also works with Part container).
In the attached file, 'Sketch' is mapped on XY plane with no offset/rotation.
However I changed the 'Body' Placement to offset 10,10,10 and rotation of 90° around X.
And now we see a difference. :P

Code: Select all

>>> App.ActiveDocument.Sketch.Placement
Placement [Pos=(0,0,0), Yaw-Pitch-Roll=(0,0,0)]
>>> App.ActiveDocument.Sketch.getGlobalPlacement()
Placement [Pos=(10,10,10), Yaw-Pitch-Roll=(0,0,90)]
Thanks, got it and it become quite simple now :D
Post Reply