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
Rotate vector around other vector (as axis)
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Re: Rotate vector around other vector (as axis)
Hello,
you can use the Rotation object with its various constructors to do that, for example by giving a rotation axis and a angle:
You can not assign them as Placement like with the document objects, but use its functions to transform the vector.
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)
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.I would like to rotate a vector a set number of degrees using its normal as an axis.
Re: Rotate vector around other vector (as axis)
Hi Ickby,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:
You can not assign them as Placement like with the document objects, but use its functions to transform the vector.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)
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.I would like to rotate a vector a set number of degrees using its normal as an axis.
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".
Re: Rotate vector around other vector (as axis)
There is also a helper tool for that in DraftVecUtils:
Code: Select all
import DraftVecUtils
rotatedVector = DraftVecUtils.rotate(myVector,angle_in_radians,normalVector)