In the example below, I'm using the yaw/pitch/roll angles. I realize that the second and third rotations would be applied to a rotated matrix, so the example would not work as shown (if all three rotations were attempted). However, I did presume that a rotation of only the yaw would return a matrix such that getYawPitchRoll would return a yaw angle equal to what I had applied (if I have misunderstood the XYZ association to YPR, I would still have expected one angle to match).
What I need is to determine the proper angles such that I can successively apply them to achieve the orientation of the z-axis I need (I need to use the rotations in this form to correspond to what is happening physically).
Code: Select all
doc = FreeCAD.ActiveDocument
# create a local coordinate system (at the origin) with an arbitrary rotation
lcs1 = doc.addObject('PartDesign::CoordinateSystem', "LCS_1")
rot = FreeCAD.Rotation(40, 62, 38)
lcs1.Placement.Rotation = rot
print(f"LCS1_YPR: {lcs1.Placement.Rotation.getYawPitchRoll()}")
lcs2 = doc.addObject('PartDesign::CoordinateSystem', "LCS_2")
yaw, pitch, roll = lcs1.Placement.Rotation.getYawPitchRoll()
# rotate the second coordinate system to match the orientation of the first
matrix = lcs2.Placement.Matrix
matrix.rotateZ(math.degrees(yaw))
# matrix.rotateX(math.degrees(pitch)) # would be applied to a rotated LCS
# matrix.rotateY(math.degrees(roll))
lcs2.Placement.Matrix = matrix
# print the final orientation of the second coordinate system
print(f"LCS2_YPR: {lcs2.Placement.Rotation.getYawPitchRoll()}")
Thanks,
--Don
Code: Select all
OS: Ubuntu 22.10 (ubuntu:GNOME/ubuntu)
Word size of FreeCAD: 64-bit
Version: 0.20.1.
Build type: Release
Python 3.10.7, Qt 5.15.4, Coin 4.0.0, Vtk 9.1.0, OCC 7.6.3
Locale: English/United States (en_US)
Installed mods:
* Curves 0.5.2
* Assembly4 0.12.3
* Manipulator 1.4.9
* fasteners 0.3.50