three questions about positioning and rotating

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
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!
Post Reply
ttype
Posts: 20
Joined: Wed May 29, 2013 12:20 pm

three questions about positioning and rotating

Post by ttype »

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...)

Image

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.

Image

3. Can I rotate an object around one of its' edges? Or any edge in the document?

Image
A StartupScript.py: http://paste.ubuntu.com/5776142/
RunMacroInPythonConsole.py: http://paste.ubuntu.com/5780306/
wmayer
Founder
Posts: 20308
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: three questions about positioning and rotating

Post by wmayer »

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...)
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.
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 only want to *view* the object from another perspective then you shouldn't rotate the object but rather the camera of the 3d view.

Code: Select all

Gui.activeDocument().activeView().viewRight()
If you insist on rotating the object you have to write:

Code: Select all

from FreeCAD import Base
App.ActiveDocument.ActiveObject.Placement.Rotation=Base.Rotation(-0.5,-0.5,-0.5,0.5)
3. Can I rotate an object around one of its' edges? Or any edge in the document?
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.

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
User avatar
wandererfan
Veteran
Posts: 6317
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: three questions about positioning and rotating

Post by wandererfan »

[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
ttype
Posts: 20
Joined: Wed May 29, 2013 12:20 pm

Re: three questions about positioning and rotating

Post by ttype »

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/
wmayer
Founder
Posts: 20308
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: three questions about positioning and rotating

Post by wmayer »

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/.
What doesn't work?
ttype
Posts: 20
Joined: Wed May 29, 2013 12:20 pm

Re: three questions about positioning and rotating

Post by ttype »

wmayer wrote:
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/.
What doesn't work?
Guess everything is working alright, it is just me having problems.
A StartupScript.py: http://paste.ubuntu.com/5776142/
RunMacroInPythonConsole.py: http://paste.ubuntu.com/5780306/
Post Reply