Moving a rotated Part in Global XYZ
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Moving a rotated Part in Global XYZ
What I am calling Global is also the screen XYZ. When I create a Part the placement angle is set to zero so everything is fine but once Part rotation occurs then moving the Part in the global XYZ gets complicated and that's what I want to do. That's my first question: Is there a way to move a rotated Part in the Global XYZ without doing a bunch of calculations?
If I'm stuck with loosing easy editing of global XYZ placements on a rotated Part what do need to do?
Here is my second question: How to go about doing this, I hope someone has done this already , here are a couple thoughts to move 1 mm.
1) Make a copy of Part (and hide it) and rotate it to zero, then move the 1 mm, then rotate back to the initial angle and copy placement to the original Part.
2) Do the trig. required to move the Part at angle 1 mm; This would be less accurate if moved a bunch.
The big picture if I see correctly: When Part is created it aligns to the global XYZ and can be moved easily (global XYZ) thru preferences but once Part is rotated the direct editing of the placement (global XYZ) is lost. It seems like the global XYZ data of a Part should be available but how to access it?????
Thanks
If I'm stuck with loosing easy editing of global XYZ placements on a rotated Part what do need to do?
Here is my second question: How to go about doing this, I hope someone has done this already , here are a couple thoughts to move 1 mm.
1) Make a copy of Part (and hide it) and rotate it to zero, then move the 1 mm, then rotate back to the initial angle and copy placement to the original Part.
2) Do the trig. required to move the Part at angle 1 mm; This would be less accurate if moved a bunch.
The big picture if I see correctly: When Part is created it aligns to the global XYZ and can be moved easily (global XYZ) thru preferences but once Part is rotated the direct editing of the placement (global XYZ) is lost. It seems like the global XYZ data of a Part should be available but how to access it?????
Thanks
Re: Moving a rotated Part in Global XYZ
In the Placement dialog, check "Apply incremental changes".
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
Re: Moving a rotated Part in Global XYZ
chrisb, while I'm not using the dialog I did read this:
I didn't know this existed. If it does what it says it is exactly what I need.
Thank you
Code: Select all
getGlobalPlacement() # return the GlobalPlacement
Thank you
Re: Moving a rotated Part in Global XYZ
Are you trying to rotate with python?
Placement is the orientation in the Global plane, there is no concept of local and global plane in Freecad.
You could do many things, the most easy to understand and quite good is using matrix (it have some problem with complex rotation and the usual gimbal lock problems) but if you do:
As example to see what are the methods try to do:
And you are presented with a list of methods and attribute of Matrix.
Now I'm on mobile so no FreeCAD available to check code so I'm using my Impaired memory, probably there are some errors in the methods name.
Hope it helps.
Regards
Carlo D.
Placement is the orientation in the Global plane, there is no concept of local and global plane in Freecad.
You could do many things, the most easy to understand and quite good is using matrix (it have some problem with complex rotation and the usual gimbal lock problems) but if you do:
Code: Select all
m = obj.Placement.Matrix
m.rotX(90)
m.move(Vector(10,20,0))
m.rotZ(75)
obj.Placement.Matrix = m
Code: Select all
print(dir(FreeCAD.Placement.Matrix))
Now I'm on mobile so no FreeCAD available to check code so I'm using my Impaired memory, probably there are some errors in the methods name.
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/
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
-
- Veteran
- Posts: 3080
- Joined: Thu Sep 24, 2020 10:31 pm
- Location: Hawaii
- Contact:
Re: Moving a rotated Part in Global XYZ
If you just want to move (translate an object), just add the translation vector to its Placement.Base
moves the object by moveBy
If you want to move and rotate again, it gets more complicated.
Code: Select all
moveBy = App.Vector(10, 20, 30)
pl = obj.Placement
pl.Base = pl.Base + moveBy
If you want to move and rotate again, it gets more complicated.
Re: Moving a rotated Part in Global XYZ
I dealt with rotations of objects nested in Part containers in Macro StraightenObject. You can have a look there.
-
- Veteran
- Posts: 3080
- Joined: Thu Sep 24, 2020 10:31 pm
- Location: Hawaii
- Contact:
Re: Moving a rotated Part in Global XYZ
Looks like you can also use:
It does exactly the same as
Take your pick!
Code: Select all
obj.Placement.move(moveBy)
Code: Select all
obj.Placement.Base = obj.Placement.Base + moveBy
Re: Moving a rotated Part in Global XYZ
Thanks all, I will digest the responses.
The goal of the macro is to select and drag/stack Part objects with a mouse and also rotate with a keyboard, it has options to drag different levels of Part, like Part in Part in Part. This all works until a parent Part is rotated.
The issue is this funtion,
I use this to get cursor position and reference it to the Part, once referenced I can directly move the mouse and move the Part or assembly of Parts. The problem is once any parent Part is rotated there is a new angled correlation between the mouse and angled placement as I move the mouse. The Part moves the correct amount just in the wrong angled direction.
It seems like a trig. fix might do it but I have been down this road a few times, I get the trig. working for X,Y and then Z comes into the picture.
I looked at using global placement but I still have the issue with the above function. I'm kind of stuck but I will look at what openBrain has done.
Thanks
The goal of the macro is to select and drag/stack Part objects with a mouse and also rotate with a keyboard, it has options to drag different levels of Part, like Part in Part in Part. This all works until a parent Part is rotated.
The issue is this funtion,
Code: Select all
self.listObjects = FreeCADGui.ActiveDocument.ActiveView.getObjectsInfo(v.getCursorPos(),0)
It seems like a trig. fix might do it but I have been down this road a few times, I get the trig. working for X,Y and then Z comes into the picture.
I looked at using global placement but I still have the issue with the above function. I'm kind of stuck but I will look at what openBrain has done.
Thanks
Re: Moving a rotated Part in Global XYZ
Take in account that each world has his rotation.
When you deal with mouse positions you are dealing with Coin3D in other word the visualization part of FreeCAD.
when you are using objects, they are stored and modeled by the "modeling engine" in other word OCCT.
So if say Coind3D use clockwise rotation convention and OCCT use counterclockwise (that is more common when dealing with mathematicha things, as it is the trigonometric convention), the angles you obtain from Coin3D are not "compatible" with those needed by OCCT.
For simple rotations, it is simple as invert them, for complex rotation, it is not so simple, but I think that in FreeCAD there is somewhere some helpers methods to do conversions between Coin3D and OCCT, to have as example the correct coordinates of a point, in the simpler user case you have to take in account the fact that zoom level might alter the correspondance by screen coordinates (that in good approximations are pixels) and "3d world" dimensions, so some math is involved, and is done somewhere in FreeCAD code.
To know where it is, or you try to inspect sources, or maybe someone might step in and gave some precise location, or methods to be used.
Hope it helps
Carlo D.
When you deal with mouse positions you are dealing with Coin3D in other word the visualization part of FreeCAD.
when you are using objects, they are stored and modeled by the "modeling engine" in other word OCCT.
So if say Coind3D use clockwise rotation convention and OCCT use counterclockwise (that is more common when dealing with mathematicha things, as it is the trigonometric convention), the angles you obtain from Coin3D are not "compatible" with those needed by OCCT.
For simple rotations, it is simple as invert them, for complex rotation, it is not so simple, but I think that in FreeCAD there is somewhere some helpers methods to do conversions between Coin3D and OCCT, to have as example the correct coordinates of a point, in the simpler user case you have to take in account the fact that zoom level might alter the correspondance by screen coordinates (that in good approximations are pixels) and "3d world" dimensions, so some math is involved, and is done somewhere in FreeCAD code.
To know where it is, or you try to inspect sources, or maybe someone might step in and gave some precise location, or methods to be used.
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/
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
Re: Moving a rotated Part in Global XYZ
I couldn't put that thought in words but Yes! that's what I was thinking.onekk wrote
to have as example the correct coordinates of a point, in the simpler user case you have to take in account the fact that zoom level might alter the correspondance by screen coordinates (that in good approximations are pixels) and "3d world" dimensions, so some math is involved, and is done somewhere in FreeCAD code.
I rotated a parent Part 180 and everything seems to move reversed so I think with XY swap and some trig., that might do the job, I'm not sure about what happens when I move in the Z direction.
I'm thinking about another approach but it has some issues also; What I want is to keep the Part (visually) under the cursor and ".getCursorPos()" does report what objects are under it. I might be able to track what ".getCursorPos()" is reporting and move the Part so it stays under the cursor. The only problem is when there is a large cursor movement.
Thanks