[Fixed] Bug on inverted Placement

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
dpoen
Posts: 49
Joined: Wed Feb 02, 2022 10:26 pm

[Fixed] Bug on inverted Placement

Post by dpoen »

Hi everyone !

I've been blaying with the python API, and especiallly the "Placement" object.
I might have found a bug :

In a console :
>>> p = FreeCAD.Placement()
>>> p.Rotation.Angle = 1.57
>>> p.inverse().Rotation.Angle
0.0

That should not be that, ins't it ? I should get -1.57, right ?

Thanks !

OS: Debian GNU/Linux 11 (bullseye) (XFCE/xfce)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.
Build type: Release
Python version: 3.9.2
Qt version: 5.15.2
Coin version: 4.0.0
OCC version: 7.5.1
Locale: English/United States (en_US)
Last edited by dpoen on Mon Jun 20, 2022 9:03 am, edited 1 time in total.
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Bug on inverted Placement

Post by openBrain »

Hello,

What you do have basically no sense. A rotation is defined by not only an angle, but also an axis.
If we don't have the axis (especially for first, but let's say for both), it's just 2 numbers.
dpoen
Posts: 49
Joined: Wed Feb 02, 2022 10:26 pm

Re: Bug on inverted Placement

Post by dpoen »

Yes, and the axis is by default (0,0,1), so the inverted rotation should either be the same angle (1.57) but with the opposite axis (0,0,-1), or use the same axis (0,0,1) but using the opposite angle (-1.57)

Both way, the rotation angle should not be 0, imo

EDIT : I just look up, and it actually choose to invert the axis, so as a follow-up to my example in my first post, if I do :
>>> p.inverse().Rotation.Axis
(0,0,-1)
That should force to display p.inverse().Rotation.Angle = 1.57

I don't agree (or I don't understand you) about "not making sense", and if it actually not make sense, I think the "inverse()" method should be removed from the Placement object.

And additionnaly, this command seems to otherwise work, considering that :
>>> p.inverse().Rotation.Matrix - p.Rotation.Matrix.inverse()
give the zero matrix :)

Hope I've got your point, and made mine clearer :)
marioalexis
Posts: 124
Joined: Wed Jun 19, 2019 7:44 pm

Re: Bug on inverted Placement

Post by marioalexis »

there is a bug in Rotation::inverse(). Only the array representing the quaternion and the Vector3D axis are changed, but not the _angle member.
marioalexis
Posts: 124
Joined: Wed Jun 19, 2019 7:44 pm

Re: Bug on inverted Placement

Post by marioalexis »

dpoen
Posts: 49
Joined: Wed Feb 02, 2022 10:26 pm

Re: Bug on inverted Placement

Post by dpoen »

Thanks you sir ! :)
User avatar
onekk
Veteran
Posts: 6215
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: [Fixed] Bug on inverted Placement

Post by onekk »

Probably this forum discussion will make some light on the matter, that is not trivial and not unique:

Angles discussion about the 24 types of Cardan angles and similar

https://forum.freecadweb.org/viewtopic. ... 5&start=20

You will see also some hints on the math behind the things, in the comment present in the source:

https://github.com/FreeCAD/FreeCAD/blob ... tation.cpp

Hope it helps.

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/
User avatar
onekk
Veteran
Posts: 6215
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Bug on inverted Placement

Post by onekk »

dpoen wrote: Fri Jun 17, 2022 8:07 pm
Thanks you sir ! :)
It seems that has been integrated in new builds.

https://github.com/FreeCAD/FreeCAD/comm ... 989800b334
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/
Post Reply