I have three questions about rotating and positioning:
1. I would like to know how to change an object's origin so that its' (0,0,0) is also the document's - world's(?) - (0,0,0). (Hope the picture explains my non native English...)
2. Also I am really having problems in understanding rotation in detail. When I import a curve I always see it in top view. To see the same in right view I would have to rotate 90° around the x axis and then 90° around the z. I somehow understand why it is not working by just setting axis to 90 and x AND z to "1", but not how to achieve what I want.
3. Can I rotate an object around one of its' edges? Or any edge in the document?
three questions about positioning and rotating
Forum rules
and Helpful information
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help
Also, be nice to others! Read the FreeCAD code of conduct!
Also, be nice to others! Read the FreeCAD code of conduct!
three questions about positioning and rotating
A StartupScript.py: http://paste.ubuntu.com/5776142/
RunMacroInPythonConsole.py: http://paste.ubuntu.com/5780306/
RunMacroInPythonConsole.py: http://paste.ubuntu.com/5780306/
Re: three questions about positioning and rotating
It's up to you to define the object's origin. Then to move this point to the origin in world coordinates just set the Position attribute of the Placement to the negative origin of the object.1. I would like to know how to change an object's origin so that its' (0,0,0) is also the document's - world's(?) - (0,0,0). (Hope the picture explains my non native English...)
If you only want to *view* the object from another perspective then you shouldn't rotate the object but rather the camera of the 3d view.2. Also I am really having problems in understanding rotation in detail. When I import a curve I always see it in top view. To see the same in right view I would have to rotate 90° around the x axis and then 90° around the z. I somehow understand why it is not working by just setting axis to 90 and x AND z to "1", but not how to achieve what I want.
Code: Select all
Gui.activeDocument().activeView().viewRight()
Code: Select all
from FreeCAD import Base
App.ActiveDocument.ActiveObject.Placement.Rotation=Base.Rotation(-0.5,-0.5,-0.5,0.5)
Yes, that's possible. The edge gives you the rotation axis, one of its endpoints gives you the rotation center and the angle is freely selectable. The idea is to first move to the rotation center, then do the rotation and afterwards move back.3. Can I rotate an object around one of its' edges? Or any edge in the document?
Code: Select all
s=Gui.Selection.getSelectionEx()[0] # get the selected object
e=s.SubObjects[0] # get the selected sub-object, i.e the edge
p=e.Curve.StartPoint
q=e.Curve.EndPoint
axis=q-p
t1=Base.Placement() # the movement to the center
t1.Base=Base.Vector(-p.x,-p.y,-p.z)
t2=Base.Placement()
t2.Rotation=Base.Rotation(axis, 25) # the rotation around the edge by e.g. 25 deg
t3=Base.Placement() # the movement back
t3.Base=p
# multiply all three operations to have one
t=t2.multiply(t1)
t=t3.multiply(t)
# now apply the placement
App.ActiveDocument.ActiveObject.Placement=t
- wandererfan
- Veteran
- Posts: 6317
- Joined: Tue Nov 06, 2012 5:42 pm
- Contact:
Re: three questions about positioning and rotating
[quote="ttype"]2. Also I am really having problems in understanding rotation in detail. When I import a curve I always see it in top view. To see the same in right view I would have to rotate 90° around the x axis and then 90° around the z. I somehow understand why it is not working by just setting axis to 90 and x AND z to "1", but not how to achieve what I want.
If you are working in the GUI, you can do these 2 rotations with the Placement dialog and the "Apply incremental changes" tick box. http://www.freecadweb.org/wiki/index.ph ... =Placement
You can also rotate around an arbitrary edge with the Placement dialog, but you'll need to calculate the axis manually (same logic as wmeyer's python code for axis).
wf
If you are working in the GUI, you can do these 2 rotations with the Placement dialog and the "Apply incremental changes" tick box. http://www.freecadweb.org/wiki/index.ph ... =Placement
You can also rotate around an arbitrary edge with the Placement dialog, but you'll need to calculate the axis manually (same logic as wmeyer's python code for axis).
wf
Re: three questions about positioning and rotating
Thank you. Especially for the snippets. I don't know whether it is me, but I am somehow having problems finding all the things that are interesting for me on http://localhost:7465/.
A StartupScript.py: http://paste.ubuntu.com/5776142/
RunMacroInPythonConsole.py: http://paste.ubuntu.com/5780306/
RunMacroInPythonConsole.py: http://paste.ubuntu.com/5780306/
Re: three questions about positioning and rotating
What doesn't work?ttype wrote:Thank you. Especially for the snippets. I don't know whether it is me, but I am somehow having problems finding all the things that are interesting for me on http://localhost:7465/.
Re: three questions about positioning and rotating
Guess everything is working alright, it is just me having problems.wmayer wrote:What doesn't work?ttype wrote:Thank you. Especially for the snippets. I don't know whether it is me, but I am somehow having problems finding all the things that are interesting for me on http://localhost:7465/.
A StartupScript.py: http://paste.ubuntu.com/5776142/
RunMacroInPythonConsole.py: http://paste.ubuntu.com/5780306/
RunMacroInPythonConsole.py: http://paste.ubuntu.com/5780306/