Converting from a different rotation system.

Need help, or want to share a macro? Post here!
keithsloan52
Posts: 1859
Joined: Mon Feb 27, 2012 5:31 pm

Re: Converting from a different rotation system.

realthunder wrote: Tue Mar 09, 2021 3:16 am
keithsloan52 wrote: Sun Mar 07, 2021 4:38 pm Look forward to testing. I guess given feature freeze it will be in 0.20 rather than 0.19, would have been good to have it make production 0.19.
Yes, PR submitted now probably will just be pending till 0.20 starts. You can test it with my release first.
@realthunder - Thanks I upped your Patreon to allow for the bonus payment and then reset it back to the normal value. As Patreon does not allow one time payments.
keithsloan52
Posts: 1859
Joined: Mon Feb 27, 2012 5:31 pm

Re: Converting from a different rotation system.

realthunder wrote: Sun Mar 07, 2021 10:17 am
keithsloan52 wrote: Fri Feb 05, 2021 2:31 pm I am trying to deal with some software that specifies rotation as x=<value> y=<value> z=<value>, where the values are passes as either degrees or radians ( Different parameter). As it is possible for more than one axis to be specified the order is important and this system does x rotation, then y, then z. What is the best way to go from the three values x,y,z to a FreeCAD placement rotation? Do I have to go via three separate rotations?
I have just added this capability to FreeCAD.Rotation.

Use FreeCAD.Rotation(seq, a, b, c) to create a rotation with rotation sequence 'seq', and angles a, b, c in degree. Use function Rotation.toEulerAngles(seq) to obtain the angles. Call this function without argument to obtain all possible sequence types. Intrinsic sequences is prefixed with 'i', while extrinsic ones has no prefix. Your pattern looks like an intrinsic rotation sequence with order xyz, so seq='ixyz'. I'll make a new release of my branch with the feature. I'll also submit a PR for this soon.

I borrow the code from OCCT gp_Quaternion::Get/SetEulerAngles().

The following Python code can be used for verification, e.g. checkRot('ixyz', 10, 20, 30)

Code: Select all

``````def checkRot(seq, a, b, c):
rot = FreeCAD.Rotation()
if seq[0] == 'i':
for axis,angle in zip(seq[1:], (a, b, c)):
if axis == 'x':
rot *= FreeCAD.Rotation(FreeCAD.Vector(1,0,0), angle)
elif axis == 'y':
rot *= FreeCAD.Rotation(FreeCAD.Vector(0,1,0), angle)
else:
rot *= FreeCAD.Rotation(FreeCAD.Vector(0,0,1), angle)
else:
for axis,angle in zip(seq, (a, b, c)):
if axis == 'x':
rot *= FreeCAD.Rotation(rot.inverted()*FreeCAD.Vector(1,0,0), angle)
elif axis == 'y':
rot *= FreeCAD.Rotation(rot.inverted()*FreeCAD.Vector(0,1,0), angle)
else:
rot *= FreeCAD.Rotation(rot.inverted()*FreeCAD.Vector(0,0,1), angle)

print(rot.toEulerAngles(seq))
return FreeCAD.Rotation(seq, a, b, c).isSame(rot, 1e-12)
``````
Trying to test this but does not appear to be in your latest build

Code: Select all

``````OS: macOS 10.15
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 2021.328.24301 +3441 (Git)
Build type: Release
Branch: LinkStage3
Hash: 0a157a307c91d241a370cdda6d8f0471b7c48915
Python version: 3.7.10
Qt version: 5.12.1
Coin version: 4.0.1
OCC version: 7.4.0
Locale: C/Default (C)
``````
Get error

Code: Select all

``````06:38:05  Traceback (most recent call last):
File "<string>", line 7, in <module>
File "/Users/keithsloan/Library/Preferences/FreeCAD/Mod/GDML/freecad/gdml/exportGDML.py", line 2261, in export
exportGDMLworld(first,filepath,fileExt)
File "/Users/keithsloan/Library/Preferences/FreeCAD/Mod/GDML/freecad/gdml/exportGDML.py", line 2062, in exportGDMLworld
exportGDML(first,filepath,fileExt)
File "/Users/keithsloan/Library/Preferences/FreeCAD/Mod/GDML/freecad/gdml/exportGDML.py", line 2010, in exportGDML
exportWorldVol(first, fileExt)
File "/Users/keithsloan/Library/Preferences/FreeCAD/Mod/GDML/freecad/gdml/exportGDML.py", line 1957, in exportWorldVol
processVolume(vol, xmlVol, xmlParent, parentName, False)
File "/Users/keithsloan/Library/Preferences/FreeCAD/Mod/GDML/freecad/gdml/exportGDML.py", line 1851, in processVolume
xmlVol, volName, xmlParent, parentName)
File "/Users/keithsloan/Library/Preferences/FreeCAD/Mod/GDML/freecad/gdml/exportGDML.py", line 1559, in processObject
processVolAssem(obj, xmlVol, volName, True)
File "/Users/keithsloan/Library/Preferences/FreeCAD/Mod/GDML/freecad/gdml/exportGDML.py", line 1867, in processVolAssem
processVolume(vol, newXmlVol, xmlParent, parentName, addVolsFlag)
File "/Users/keithsloan/Library/Preferences/FreeCAD/Mod/GDML/freecad/gdml/exportGDML.py", line 1851, in processVolume
xmlVol, volName, xmlParent, parentName)
File "/Users/keithsloan/Library/Preferences/FreeCAD/Mod/GDML/freecad/gdml/exportGDML.py", line 1593, in processObject
xmlParent, parentName)
File "/Users/keithsloan/Library/Preferences/FreeCAD/Mod/GDML/freecad/gdml/exportGDML.py", line 1520, in processBooleanObject
boolCnt, boolxml, solidName = processSolid(obj, True)
File "/Users/keithsloan/Library/Preferences/FreeCAD/Mod/GDML/freecad/gdml/exportGDML.py", line 1379, in processSolid
processRotation(obj.Tool,subtract)
File "/Users/keithsloan/Library/Preferences/FreeCAD/Mod/GDML/freecad/gdml/exportGDML.py", line 652, in processRotatio<class 'TypeError'>: function takes exactly 0 arguments (1 given)
``````
I also notice that the error is not at 652, but the toEuler call is in the function processRotation and if I alter it to toEuler() from toEuler('ixyz') I don't get the error.

You mention try in Assembler3, Is that just a case of installing the Assembler3 workbench?

Reason I have been slow to test is on import I get a load of messages that I don't get with FreeCAD i.e FreeCAD 0.19.1

Code: Select all

``````6:34:17  DeprecationWarning: Second argument is deprecated. It is ignored and will be removed in future versions. The default Python feature proxy is used for extension method overrides.
06:34:17  DeprecationWarning: Second argument is deprecated. It is ignored and will be removed in future versions. The default Python feature proxy is used for extension method overrides.
06:34:17  DeprecationWarning: Second argument is deprecated. It is ignored and will be removed in future versions. The default Python feature proxy is used for extension method overrides.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  DeprecationWarning: Second argument is deprecated. It is ignored and will be removed in future versions. The default Python feature proxy is used for extension method overrides.
06:34:17  DeprecationWarning: Second argument is deprecated. It is ignored and will be removed in future versions. The default Python feature proxy is used for extension method overrides.
06:34:17  DeprecationWarning: Second argument is deprecated. It is ignored and will be removed in future versions. The default Python feature proxy is used for extension method overrides.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  Recompute failed! Please check report view.
06:34:17  End processing GDML file``````
realthunder
Posts: 1963
Joined: Tue Jan 03, 2017 10:55 am

Re: Converting from a different rotation system.

keithsloan52 wrote: Fri Apr 02, 2021 5:45 am I also notice that the error is not at 652, but the toEuler call is in the function processRotation and if I alter it to toEuler() from toEuler('ixyz') I don't get the error.
toEuler() is the old function. The function I added is called toEulerAngles(). The source code here that can be found at here. But as the changes are in the C++ code, I am afraid you get that easily with your workbench. Once you've tested it, I will submit it to upstream.

You mention try in Assembler3, Is that just a case of installing the Assembler3 workbench?
I mean try it using my branch.

Reason I have been slow to test is on import I get a load of messages that I don't get with FreeCAD i.e FreeCAD 0.19.1
Do you mean you get the recompute failure when loading file using my branch? Can you please post some sample file here?
Try Assembly3 (latest version 0.11) along with my custom build of FreeCAD at here.
And if you'd like to show your support, you can donate through patreon, liberapay, or paypal
keithsloan52
Posts: 1859
Joined: Mon Feb 27, 2012 5:31 pm

Re: Converting from a different rotation system.

toEuler('ixyz') was coded in branch link3 which I have only just pushed to the Github repro, it was what I was testing on locally.

On my system I get error

Code: Select all

``````17:17:56  Export Rotation
17:17:56  Traceback (most recent call last):
File "<string>", line 7, in <module>
File "/Users/keithsloan/Library/Preferences/FreeCAD/Mod/GDML/freecad/gdml/exportGDML.py", line 2261, in export
exportGDMLworld(first,filepath,fileExt)
File "/Users/keithsloan/Library/Preferences/FreeCAD/Mod/GDML/freecad/gdml/exportGDML.py", line 2062, in exportGDMLworld
exportGDML(first,filepath,fileExt)
File "/Users/keithsloan/Library/Preferences/FreeCAD/Mod/GDML/freecad/gdml/exportGDML.py", line 2010, in exportGDML
exportWorldVol(first, fileExt)
File "/Users/keithsloan/Library/Preferences/FreeCAD/Mod/GDML/freecad/gdml/exportGDML.py", line 1960, in exportWorldVol
processAssembly(vol, xmlVol, xmlParent, parentName, False)
File "/Users/keithsloan/Library/Preferences/FreeCAD/Mod/GDML/freecad/gdml/exportGDML.py", line 1798, in processAssembly
processVolAssem(obj, xmlVol, volName, addVolsFlag)
File "/Users/keithsloan/Library/Preferences/FreeCAD/Mod/GDML/freecad/gdml/exportGDML.py", line 1867, in processVolAssem
processVolume(vol, newXmlVol, xmlParent, parentName, addVolsFlag)
File "/Users/keithsloan/Library/Preferences/FreeCAD/Mod/GDML/freecad/gdml/exportGDML.py", line 1851, in processVolume
xmlVol, volName, xmlParent, parentName)
File "/Users/keithsloan/Library/Preferences/FreeCAD/Mod/GDML/freecad/gdml/exportGDML.py", line 1559, in processObject
processVolAssem(obj, xmlVol, volName, True)
File "/Users/keithsloan/Library/Preferences/FreeCAD/Mod/GDML/freecad/gdml/exportGDML.py", line 1867, in processVolAssem
processVolume(vol, newXmlVol, xmlParent, parentName, addVolsFlag)
File "/Users/keithsloan/Library/Preferences/FreeCAD/Mod/GDML/freecad/gdml/exportGDML.py", line 1851, in processVolume
xmlVol, volName, xmlParent, parentName)
File "/Users/keithsloan/Library/Preferences/FreeCAD/Mod/GDML/freecad/gdml/exportGDML.py", line 1559, in processObject
processVolAssem(obj, xmlVol, volName, True)
File "/Users/keithsloan/Library/Preferences/FreeCAD/Mod/GDML/freecad<class 'TypeError'>: function takes exactly 0 arguments (1 given)
``````
Not sure why it does not report the actual/correct function and line number, but when I change back to toEuler() the error goes away
and some things are not rotated correctly. I have a smaller file that also shows the export rotation issue but unfortunately not allowed to share as confidential.

The file is as per first item of issue 40 see https://github.com/KeithSloan/GDML/issues/40
rich_mirror12_457.gdml

On Pauly system it takes 3 or 5 mins to load/import on my system it is more like 15 mins with 11 mins CPU (666 secs)
He is using some flavour of Linux and looks okay, but export then reimport shows some items not rotated correctly.

Think I need to learn how to use an interactive debugger and get rid of all the trace calls or at least comment them out
might help a bit.

Export is very quick, so quick one thinks it cannot possibly have worked.

My system LinkStage 3 info

Code: Select all

``````OS: macOS 10.15
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 2021.328.24301 +3441 (Git)
Build type: Release
Branch: LinkStage3
Hash: 0a157a307c91d241a370cdda6d8f0471b7c48915
Python version: 3.7.10
Qt version: 5.12.1
Coin version: 4.0.1
OCC version: 7.4.0
Locale: C/Default (C)
``````
Thanks for your help
Keith
keithsloan52
Posts: 1859
Joined: Mon Feb 27, 2012 5:31 pm

Re: Converting from a different rotation system.

Tried toEulerAngles('ixyz') Same result wants zero parameters
realthunder
Posts: 1963
Joined: Tue Jan 03, 2017 10:55 am

Re: Converting from a different rotation system.

keithsloan52 wrote: Sun Apr 04, 2021 5:36 pm Tried toEulerAngles('ixyz') Same result wants zero parameters
I have submitted a PR to your GDML github repo. Make sure you test it with my release, preferable the latest Daily release. I was able to import the rich_mirror gdml file in just 6 seconds.
Try Assembly3 (latest version 0.11) along with my custom build of FreeCAD at here.
And if you'd like to show your support, you can donate through patreon, liberapay, or paypal
keithsloan52
Posts: 1859
Joined: Mon Feb 27, 2012 5:31 pm

Re: Converting from a different rotation system.

realthunder wrote: Mon Apr 12, 2021 6:34 am
keithsloan52 wrote: Sun Apr 04, 2021 5:36 pm Tried toEulerAngles('ixyz') Same result wants zero parameters
I have submitted a PR to your GDML github repo. Make sure you test it with my release, preferable the latest Daily release. I was able to import the rich_mirror gdml file in just 6 seconds.
Great news Zheng - Look forward to testing. Who knows we might even get to the state where importing Alice.gdml and other CERN experiments is practical.

By the way is Zheng first or second name, I have a vague impression that some Asian Societies use family name first, but could be wrong?
realthunder
Posts: 1963
Joined: Tue Jan 03, 2017 10:55 am

Re: Converting from a different rotation system.

keithsloan52 wrote: Mon Apr 12, 2021 8:53 am By the way is Zheng first or second name, I have a vague impression that some Asian Societies use family name first, but could be wrong?
Yes, that's my family name, and we do put it first
Try Assembly3 (latest version 0.11) along with my custom build of FreeCAD at here.
And if you'd like to show your support, you can donate through patreon, liberapay, or paypal
keithsloan52
Posts: 1859
Joined: Mon Feb 27, 2012 5:31 pm

Re: Converting from a different rotation system.

realthunder wrote: Mon Apr 12, 2021 9:22 am
keithsloan52 wrote: Mon Apr 12, 2021 8:53 am By the way is Zheng first or second name, I have a vague impression that some Asian Societies use family name first, but could be wrong?
Yes, that's my family name, and we do put it first
Thanks Lei Good to Know
realthunder
Posts: 1963
Joined: Tue Jan 03, 2017 10:55 am

Re: Converting from a different rotation system.

PR submitted here for the new API.
Try Assembly3 (latest version 0.11) along with my custom build of FreeCAD at here.
And if you'd like to show your support, you can donate through patreon, liberapay, or paypal