Rotate about non-global axis

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!
dam5h
Posts: 30
Joined: Mon Feb 11, 2013 4:24 pm

Rotate about non-global axis

Postby dam5h » Wed Apr 17, 2013 5:01 pm

Hello,

I need some help on determining if this is possible with FreeCAD api. I have a part already made (which is not centered on its Placement "position") and now want to rotate about a non-global axis which passes through the part center (not the Placement "position"). I want to define the axis of rotation but not translate the part relative to the rotation point, if that makes sense?

My understanding of performing a rotation is as follows:

Use the Placement dialog or use python:

Code: Select all

part.Placement = FreeCAD.Placement(...)
I have been using this with some sucess when the axis of rotation passes through the part's "position" definition, I simply define the 'angle' and the 'axis'. I realize axis can be custom, but it still seems to be missing a 'pnt' parameter to be fully defined as an axis alone is only an orientation but still has translational DOF's. If I change the 'position' parameters that actually may translate the part in addition to the custom rotation, which I need to avoid.

This means if I define a part such that its local priciple axis is not at global coordinates 0, 0, 0 then I am having difficulty rotating it about that principal axis while keeping its center of gravity in the same location.

Thanks
User avatar
wandererfan
Posts: 4078
Joined: Tue Nov 06, 2012 5:42 pm

Re: Rotate about non-global axis

Postby wandererfan » Thu Apr 18, 2013 1:24 pm

Is this (attachment) the sort of thing you want? It's a box rotated about an axis passing through the centre of the box. It was done using the Placement dialog in the Gui. If it's close, we can figure out what the corresponding Py code looks like.

wf
Attachments
RotateCoG.fcstd
(9.53 KiB) Downloaded 56 times
dam5h
Posts: 30
Joined: Mon Feb 11, 2013 4:24 pm

Re: Rotate about non-global axis

Postby dam5h » Thu Apr 18, 2013 8:37 pm

Thank you for doing this visualization. The main difference here is that "AxisofRot" passes through the origin, I would like to rotate about an axis that does not pass through the origin. For example I would like to rotate the box about one for your black lines instead of the orange one. The orientation of those are acually the same as the global x, y, z but the difference is that they do not pass through the global origin. If I define the axis as [1, 0, 0] and give a rotation angle, the box would move like a planet around the sun, I need it to stay stationary relative to the sun and spin in place around a local axis that doesn't pass through the global origin.

Thanks again.
User avatar
wandererfan
Posts: 4078
Joined: Tue Nov 06, 2012 5:42 pm

Re: Rotate about non-global axis

Postby wandererfan » Thu Apr 18, 2013 10:42 pm

"seems to be missing a 'pnt' parameter to be fully defined as an axis"

I think your 'pnt' is "center" in FreeCAD terminology.

If we start with the same little box with it's CoG at (25,25,15) (attachment) and run this code, the box should spin around a local Z.

Code: Select all

import FreeCAD
obj = App.ActiveDocument.Extrude                          # our box
rot = FreeCAD.Rotation(FreeCAD.Vector(0,0,1),45)   # 45 about Z
centre = FreeCAD.Vector(25,25,0)                             # "centre" of rotation (where local Z cuts XY)
pos = obj.Placement.Base                                        # original placement of obj 
newplace = FreeCAD.Placement(pos,rot,centre)       
obj.Placement = newplace  
wf
Attachments
RotateCoG2.fcstd
(9.23 KiB) Downloaded 543 times
mario52
Posts: 3222
Joined: Wed May 16, 2012 2:13 pm

Re: Rotate about non-global axis

Postby mario52 » Fri Apr 19, 2013 8:48 am

Hello wandererfan
can add you your script and the file in wiki "Placement", in a section ==Script == with a comment ?
Thanks mario
(translate by Bing)
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting, Dialog creation. My macros on Gist.github.
User avatar
wandererfan
Posts: 4078
Joined: Tue Nov 06, 2012 5:42 pm

Re: Rotate about non-global axis

Postby wandererfan » Fri Apr 19, 2013 2:08 pm

mario52 wrote:Hello wandererfan
can add you your script and the file in wiki "Placement", in a section ==Script == with a comment ?
Thanks mario
(translate by Bing)
Bonjour, mario52. I can add the script with some comments, but is it possible to add fcstd file to wiki?

wf
dam5h
Posts: 30
Joined: Mon Feb 11, 2013 4:24 pm

Re: Rotate about non-global axis

Postby dam5h » Fri Apr 19, 2013 3:14 pm

I see, so you rotate first and then translate to get the same result. In hindsight this is obvious, my problem was trying to accomplish with one rotate command!

Thanks very much!
mario52
Posts: 3222
Joined: Wed May 16, 2012 2:13 pm

Re: Rotate about non-global axis

Postby mario52 » Fri Apr 19, 2013 4:11 pm

Hi
wandererfan wrote: but is it possible to add fcstd file to wiki?
I tried to import it by changing the extension to .png but it doesn't work! the system did seem to accept that "real" png, gif, jpg, jpeg.
mario
Last edited by mario52 on Sat Apr 20, 2013 8:29 am, edited 1 time in total.
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting, Dialog creation. My macros on Gist.github.
User avatar
NormandC
Posts: 18534
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: Rotate about non-global axis

Postby NormandC » Sat Apr 20, 2013 3:55 am

(English version below)

Mario stp, réponds en anglais sur ce forum. L'écrasante majorité des membres du forum ne parle pas français. L'anglais est la langue commune ici, ça n'est pas aux autres de traduire ton message en anglais pour pouvoir le comprendre.

Mario please answer in English in this forum. An overwhelming majority of forum members do not speak French. English is the common language here, It is not right to ask others to translate your post themselves so they can understand you.

To answer the question, the wiki does not currently accept fcstd files. It's been briefly discussed in the Open Discussion forum (although I don't remember which topic), but nothing was decided. It was brought up by jmaustpc IIRC.
mario52
Posts: 3222
Joined: Wed May 16, 2012 2:13 pm

Re: Rotate about non-global axis

Postby mario52 » Sat Apr 20, 2013 9:51 am

Hi

Indeed I found these discussions
(en effet j'ai trouvé ces discussions )

Wiki file extension attachment permission for fcstd

"Sorry, the board attachment quota has been reached"

Documenting in WIKI

mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting, Dialog creation. My macros on Gist.github.