How to add offset at Placement.Rotation.Axis ?

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
manos
Posts: 432
Joined: Thu Nov 12, 2020 10:48 am
Location: Greece

How to add offset at Placement.Rotation.Axis ?

Post by manos »

Code: Select all

#print(' Global Placement before',obj.getGlobalPlacement())
sel=FreeCADGui.Selection.getSelectionEx()[0]
obj=sel.Object
v1 = App.Vector(1,1,1) 
v2=App.Vector(6,7,9)
obj.Placement.Base=v2
obj.Placement.Rotation.Axis=v1  
obj.Placement.Rotation.Angle=0.3
#obj.Placement.Rotation.Center=(1,0,0)
print(' Global Placement after',obj.getGlobalPlacement())
print('---------End---------')
I need to add an offset to obj.Placement.Rotation.Axis . At Sandbox:@Edwilliams16 there is such example, but uses App. (https://wiki.freecadweb.org/Sandbox:Edw ... #Rotations)
I prefer -if possible- to use the selected object as above.

Any help welcomed.
User avatar
onekk
Veteran
Posts: 6205
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: How to add offset at Placement.Rotation.Axis ?

Post by onekk »

manos wrote: Sun Sep 25, 2022 8:59 am ...
Any help welcomed.

Code: Select all

from FreeCAD import Rotation 
rot = Rotation(v2, 30) 
rotVec = rot.multVec(v1)
You are referring to this code.

In this case what is the result of doing something similar to:

Code: Select all

from FreeCAD import Rotation 
rot = obj.Placement.Rotation 
rotVec = rot.multVec(v1)
The example is using a Rotation, you inted to use an "existing" rotation, and multiply it by a "translation vector".

usually when having problem I use the Matrix form that has the ability to be additive:

Code: Select all

m = obj.Placement.Matrix

m.move()
m.rotateX()
m.rotateY()

obj.Placement.Matrix = m

Code: Select all

help(FreeCAD.Matrix)
will give you an idea about the transformations that you could apply.

Hope it helps.

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/
manos
Posts: 432
Joined: Thu Nov 12, 2020 10:48 am
Location: Greece

Re: How to add offset at Placement.Rotation.Axis ?

Post by manos »

onekk wrote: Sun Sep 25, 2022 9:08 am
Carlo D.
Thanks onekk I will try it.
User avatar
onekk
Veteran
Posts: 6205
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: How to add offset at Placement.Rotation.Axis ?

Post by onekk »

manos wrote: Sun Sep 25, 2022 9:26 am Thanks onekk I will try it.
I've forgotten to say that Matrix is however "stored" as a quaternion internally.

In other word the transformation is applied, and some calculations could be done using Matrix, but the result is stored in a quaternion and "translated" in a Matrix representation so, if there are "equivalent" transformation probably the process of translate, operate on the matrix, save as quaternion and translate the quaternion in matrix, could not permit to as example make some test between the Matrix.

Same as when you specify rotation of more than 360 degree and then when retrieving the Placement you have them "normalised" in the range of 0 - 360.

There are some forum post that mark this as a bug, but this is the way FC and probably OCCT store things, there are around some post that discuss this thing, but sadly I have not noted them. So take it as a "to be verified" answer.

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/
manos
Posts: 432
Joined: Thu Nov 12, 2020 10:48 am
Location: Greece

Re: How to add offset at Placement.Rotation.Axis ?

Post by manos »

onekk wrote: Sun Sep 25, 2022 9:08 am

Code: Select all

from FreeCAD import Rotation 
rot = Rotation(v2, 30) 
rotVec = rot.multVec(v1)
I suppose v2 is the obj(.Placement.)Rotation.Axis = The direction of the Axis
30 is the obj(.Placement.)Rotation.Angle
v1 is the offset of the obj(.Placement.)Rotation.Axis
...
In this case what is the result of doing something similar to:

Code: Select all

from FreeCAD import Rotation 
rot = obj.Placement.Rotation 
rotVec = rot.multVec(v1)
Probably you mean: In this case That is the result of doing something similar to:

Do you agree to those notes Carlo ? Thanks for your time.
User avatar
onekk
Veteran
Posts: 6205
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: How to add offset at Placement.Rotation.Axis ?

Post by onekk »

manos wrote: Sun Sep 25, 2022 10:33 am
onekk wrote: Sun Sep 25, 2022 9:08 am

Code: Select all

from FreeCAD import Rotation 
rot = Rotation(v2, 30) 
rotVec = rot.multVec(v1)
Rotation is composed in many ways, probably this is the form:

Code: Select all

Rotation(Axis, angle)

Code: Select all

help(FreeCAD.Rotation)
Should do some hints.

you could use many ways when specificing rotations, as it is very flexible but complex.

Probably the most difficult part of Placement

Now I'm not at computer so I'm using my "impaired" memory.

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/
manos
Posts: 432
Joined: Thu Nov 12, 2020 10:48 am
Location: Greece

Re: How to add offset at Placement.Rotation.Axis ?

Post by manos »

onekk wrote: Sun Sep 25, 2022 11:00 am
Regards

Carlo D.
OK Carlo thanks a lot.
Post Reply