Rotate vector around other vector (as axis)

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
Chairy
Posts: 19
Joined: Mon Mar 17, 2014 8:14 am

Rotate vector around other vector (as axis)

Post by Chairy »

Hi,

Here comes yet another thread, many questions sorry!

I would like to rotate a vector a set number of degrees using its normal as an axis.
I have looked through several previous threads about this problem but I have not found anything that solves my problem.
It would be nice to use a rotation method available in FreeCAD. However the methods I have found (.Placement, .rotate) are only defined for shapes or objects, not vectors declared using App.Vector(). Several of the threads are also old (2010) making me uncertain whether or not they are still accurate. How do I rotate a vector around a specified axis (unit vector)? Do I need to define the quaternion? If this is the case, is there a method calculating it for me using the vector and set axis or do I need to calculate it manually?

I am currently using the stable 0.13 version as I have had issues running Spyder with the latest unstable releases.

Thanks
ickby
Veteran
Posts: 3116
Joined: Wed Oct 05, 2011 7:36 am

Re: Rotate vector around other vector (as axis)

Post by ickby »

Hello,

you can use the Rotation object with its various constructors to do that, for example by giving a rotation axis and a angle:

Code: Select all

>>> rot = App.Rotation(App.Vector(1,0,0), 90)
>>> rot.multVec(App.Vector(0,1,0))
Vector (0.0, 2.2204460492503131e-16, 1.0)
You can not assign them as Placement like with the document objects, but use its functions to transform the vector.
I would like to rotate a vector a set number of degrees using its normal as an axis.
If you by "its normal" mean a perpendicular vector than the rotation is not fully defined, as there exist an infinite number of those, and therefore a infinite number of possible rotations can be derived. If you mean rotate around its direction than the rotation is quite useless, as the result will always be the initial vector.
Chairy
Posts: 19
Joined: Mon Mar 17, 2014 8:14 am

Re: Rotate vector around other vector (as axis)

Post by Chairy »

ickby wrote:Hello,

you can use the Rotation object with its various constructors to do that, for example by giving a rotation axis and a angle:

Code: Select all

>>> rot = App.Rotation(App.Vector(1,0,0), 90)
>>> rot.multVec(App.Vector(0,1,0))
Vector (0.0, 2.2204460492503131e-16, 1.0)
You can not assign them as Placement like with the document objects, but use its functions to transform the vector.
I would like to rotate a vector a set number of degrees using its normal as an axis.
If you by "its normal" mean a perpendicular vector than the rotation is not fully defined, as there exist an infinite number of those, and therefore a infinite number of possible rotations can be derived. If you mean rotate around its direction than the rotation is quite useless, as the result will always be the initial vector.
Hi Ickby,
thanks for this. I did not understand that you actually create a rotation and then apply it to your vector.
Regarding rotation around its normal, of course you are right. I am actually seeking to rotate a face tangent around a face normal, so this is what I am referring to when I write "its normal".
User avatar
yorik
Founder
Posts: 13665
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Rotate vector around other vector (as axis)

Post by yorik »

There is also a helper tool for that in DraftVecUtils:

Code: Select all

import DraftVecUtils
rotatedVector = DraftVecUtils.rotate(myVector,angle_in_radians,normalVector)
Post Reply