Expression doesn't update property correctly
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
Be nice to others! Read the FreeCAD code of conduct!
Re: Expression doesn't update property correctly
When dealing with rotations you have to be aware of some things.
Precedence of axis there are no a unique convention but at more than 20. I could post later a link where this matter is discussed.
If you use valued bigger than 1.0 you are not using normalized values.
the gimbal lock problem
the fact that a rotation as a sense if it is limited to a turn (0 - 360 degrees) a rotation of 370 degree is equivalent to a rotation of 10 degree, final position of solid is the same.
When things get hard, I usually use Matrix even if they are not perfect (gimbal lock) they permit to apply rotation in the desired order, but I usually script my work so it is a very low level approach.
Later I will post the link when I have fired up my computing machine. Now I'm using a dumbphone.
Regards
Carlo D.
Precedence of axis there are no a unique convention but at more than 20. I could post later a link where this matter is discussed.
If you use valued bigger than 1.0 you are not using normalized values.
the gimbal lock problem
the fact that a rotation as a sense if it is limited to a turn (0 - 360 degrees) a rotation of 370 degree is equivalent to a rotation of 10 degree, final position of solid is the same.
When things get hard, I usually use Matrix even if they are not perfect (gimbal lock) they permit to apply rotation in the desired order, but I usually script my work so it is a very low level approach.
Later I will post the link when I have fired up my computing machine. Now I'm using a dumbphone.
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/
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
Re: Expression doesn't update property correctly
Workaround is to set an expression on the Axis instead. There it is no problem with a non normalized vector.
But it should work on the individual values too or else the expression button should be removed from them.
Code: Select all
create(<<vector>>;1;1;1)
Re: Expression doesn't update property correctly
First thing, link promised:
https://forum.freecadweb.org/viewtopic. ... 5&start=20
Second thing, here it is working as expected:
see:
with this FC version:
Regards
Carlo D.
https://forum.freecadweb.org/viewtopic. ... 5&start=20
Second thing, here it is working as expected:
see:
with this FC version:
Code: Select all
OS: Artix Linux (openbox)
Word size of FreeCAD: 64-bit
Version: 0.20.1.29410 (Git) AppImage
Build type: Release
Branch: (HEAD detached at 0.20.1)
Hash: f5d13554ecc7a456fb6e970568ae5c74ba727563
Python 3.10.5, Qt 5.15.4, Coin 4.0.0, Vtk 9.1.0, OCC 7.6.2
Locale: Italian/Italy (it_IT)
Installed mods:
* QuickMeasure 2022.10.28
* Assembly4 0.12.4
* fasteners 0.4.24
* toSketch 1.0.1
* Curves 0.6.1
* Help 1.0.3
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/
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
Re: Expression doesn't update property correctly
The thing is if you replace the expression with a new one that gives the same result you force a recalculation and for each recalculation you get closer to expected result. Try to replace your expressions with:
1 * 1 / sqrt(2)
1 * 1 / sqrt(2)
1 * 1 * 0
What is your immediate result then?
1 * 1 / sqrt(2)
1 * 1 / sqrt(2)
1 * 1 * 0
What is your immediate result then?
Also note that in your row for Placement it shows [(0.62 0,58 0,58);....
Re: Expression doesn't update property correctly
Jolbas wrote: ↑Wed Dec 07, 2022 8:41 am The thing is if you replace the expression with a new one that gives the same result you force a recalculation and for each recalculation you get closer to expected result. Try to replace your expressions with:
1 * 1 / sqrt(2)
1 * 1 / sqrt(2)
1 * 1 * 0
What is your immediate result then?
No it is not at least for me:
and:
with 90 degree in Angle and the rotation as above, I will obtain
Code: Select all
obj.Placement.toMatrix()
Matrix ((0.5,0.5,0.707107,0),(0.5,0.5,-0.707107,0),(-0.707107,0.707107,0,0),(0,0,0,1))
obj.Placement.Rotation
Rotation (0.5, 0.5, 0.0, 0.7071067811865476)
obj.Placement.Rotation.Axis
Vector (0.7071067811865476, 0.7071067811865476, 0.0)
obj.Placement.Rotation.Angle
1.5707963267948966
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/
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
Re: Expression doesn't update property correctly
Ok @onekk . So this is not affecting all versions? The main difference is that I have a macOS:
I get this results from python console. Resetting the Axis first:
Code: Select all
OS: macOS 10.16
Word size of FreeCAD: 64-bit
Version: 0.20.1.29410 (Git)
Build type: Release
Branch: (HEAD detached at 0.20.1)
Hash: f5d13554ecc7a456fb6e970568ae5c74ba727563
Python 3.10.5, Qt 5.15.4, Coin 4.0.0, Vtk 9.1.0, OCC 7.6.2
Locale: C/Default (C)
Installed mods:
* kugghjul.py
* dxf-library
* fcgear 1.0.0
* __pycache__
* sheetmetal 0.2.53
* Curves 0.5.6
* Assembly4 0.12.4
Code: Select all
>>> obj.setExpression('.Placement.Rotation.Axis.x',None)
>>> obj.setExpression('.Placement.Rotation.Axis.y',None)
>>> obj.setExpression('.Placement.Rotation.Axis.z',None)
>>> obj.Placement.Rotation.Axis.x = 1
>>> obj.Placement.Rotation.Axis.y = 0
>>> obj.Placement.Rotation.Axis.z = 0
>>> obj.Placement.Rotation.Axis
Vector (1.0, 0.0, 0.0)
>>> obj.setExpression('.Placement.Rotation.Axis.x', '1 * 1 / sqrt(3)')
>>> obj.Placement.Rotation.Axis
Vector (1.0, 0.0, 0.0)
>>> obj.setExpression('.Placement.Rotation.Axis.y', '1 * 1 / sqrt(3)')
>>> obj.Placement.Rotation.Axis
Vector (1.0, 0.0, 0.0)
>>> obj.setExpression('.Placement.Rotation.Axis.z', '1 * 1 / sqrt(3)')
>>> obj.Placement.Rotation.Axis
Vector (1.0, 0.0, 0.0)
>>> obj.recompute()
True
>>> obj.Placement.Rotation.Axis
Vector (0.7499999999999999, 0.43301270189221935, 0.5000000000000001)
- adrianinsaval
- Veteran
- Posts: 5553
- Joined: Thu Apr 05, 2018 5:15 pm
Re: Expression doesn't update property correctly
I can reproduce similar errors without using expressions but by assigning values to Axis parts in python console.
If I set the axis vector to a non normalized vector:
Then I can ask for the RawAxis
Returns: Vector (1.0, 1.0, 1.0)
And the Axis attribute returns a normalized vector
Returns: Vector (0.5773502691896258, 0.5773502691896258, 0.5773502691896258)
This all seems to be good, but if I change one of the Axis parameters a normalization event is applied on the RawAxis. Appearantly before assigning the new value which gives unexpexted result:
Returns: Vector (0.5773502691896258, 0.5773502691896258, 2.0)
And
Returns: Vector (0.2672612419124244, 0.2672612419124244, 0.9258200997725514)
Which is a normalized representation of RawAxis
If I set the axis vector to a non normalized vector:
Code: Select all
obj.Placement.Rotation.Axis = App.Vector(1,1,1)
Code: Select all
obj.Placement.Rotation.RawAxis
And the Axis attribute returns a normalized vector
Code: Select all
obj.Placement.Rotation.Axis
This all seems to be good, but if I change one of the Axis parameters a normalization event is applied on the RawAxis. Appearantly before assigning the new value which gives unexpexted result:
Code: Select all
obj.Placement.Rotation.Axis.z = 2
obj.Placement.Rotation.RawAxis
And
Code: Select all
obj.Placement.Rotation.Axis
Which is a normalized representation of RawAxis
Re: Expression doesn't update property correctly
@onekk Do you get expected results from python commands above?