Apply Rotation to a set of cords
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Apply Rotation to a set of cords
I just want to apply a quaternion rotation a set of cords
is there simple way to do that without actually doing it a hacky way, like rotating an object and checking vertex cords
eg.new cords=qrotate(cords,quat)
is there simple way to do that without actually doing it a hacky way, like rotating an object and checking vertex cords
eg.new cords=qrotate(cords,quat)
Re: Apply Rotation to a set of cords
Please put always the info requested:
http://forum.freecadweb.org/viewtopic.php?f=3&t=2264
or at least what version of FC you are using.
and speaking of Python scripting and macro, use the </> button to insert code.
As you are writing on a code section, "speak with code", it is more clear and not ambigous.
New vertex coordinates probably could be obtained using transformations, matrix, but without code is difficult to answer as it depend on what objects are you using and how it is constructed.
Regards
Carlo D.
http://forum.freecadweb.org/viewtopic.php?f=3&t=2264
or at least what version of FC you are using.
and speaking of Python scripting and macro, use the </> button to insert code.
As you are writing on a code section, "speak with code", it is more clear and not ambigous.
New vertex coordinates probably could be obtained using transformations, matrix, but without code is difficult to answer as it depend on what objects are you using and how it is constructed.
Regards
Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
Re: Apply Rotation to a set of cords
I just want to perform a quat rotation on a coordinate and get an output coordinate
Eg
Result coords = quaternion-rotate ( [x,y,z] , [w,x,y,z] ]
I dont want to perform it on an object,
Xyz in xyz out
Eg
Result coords = quaternion-rotate ( [x,y,z] , [w,x,y,z] ]
I dont want to perform it on an object,
Xyz in xyz out
Re: Apply Rotation to a set of cords
Vasten wrote:
I don't know what version of FC are you using.
I've tested it on 0.20R29076 (Git)
Please always put your FC info as this could be important to give you a correct answer.
Rotation could be expressed as quaternion.
Code: Select all
iimport FreeCAD
from FreeCAD import Placement, Rotation, Vector
pt = Part.Point(Vector(10, 10, 0))
a = Part.Vertex(pt)
Part.show(a, "VTX_a")
c = Part.Vertex(pt)
c.Placement = FreeCAD.Placement(Vector(0,0,0), Rotation(45.0, 0.0, 0.0))
qc = c.Placement.Rotation.Q
Part.show(c, "VTX_c")
for idx in range(0,5):
d = Part.Vertex(pt)
angle = 45.0
rot = FreeCAD.Rotation(angle * idx, 0.0, 0.0)
rotq = rot.Q
d.Placement = FreeCAD.Placement(Vector(0,0,0), Rotation(*rotq))
Part.show(d, f"VTX_d{idx}")
rot is returned already as quaternion, at least in Python Console, but as there is the Q property, best is to use it.
Note that when assigning the property to Rotation the python expansion operator * as Q is returned as tuple and Rotation needs four floats to specify a Quaternion.
I don't know because I'm not very proficient in math if there is a way to "manipulate quaternions" in FC with some methods.
You could have more info writing in Python Console:
Code: Select all
print(FreeCAD.Rotation.__doc__)
or maybe:
help(FreeCAD.Rotation)
Hope it helps.
Regards
Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
-
- Veteran
- Posts: 3191
- Joined: Thu Sep 24, 2020 10:31 pm
- Location: Hawaii
- Contact:
Re: Apply Rotation to a set of cords
You can get the constructors for App.Rotation by typing into the python console and referring to the tooltip. To create the rotation represented by the quaternion q = w +xi +yj +zj use
and to apply it to a vector (u, v, w)
or more compactly, using the overloaded * operator (which also works for compounding rotations):
Code: Select all
rot = App.Rotation(x, y, z, w)
Code: Select all
rotated_vector = rot.multVec(App.Vector(u, v, w))
Code: Select all
rotated_vector = rot * App.Vector(u, v, w)
Re: Apply Rotation to a set of cords
edwilliams16 wrote: ↑Fri Jun 17, 2022 4:52 pm You can get the constructors for App.Rotation by typing into the python console and referring to the tooltip. To create the rotation represented by the quaternion q = w +xi +yj +zj useand to apply it to a vector (u, v, w)Code: Select all
rot = App.Rotation(x, y, z, w)
or more compactly, using the overloaded * operator (which also works for compounding rotations):Code: Select all
rotated_vector = rot.multVec(App.Vector(u, v, w))
Code: Select all
rotated_vector = rot * App.Vector(u, v, w)
Perfect.. exactly what I needed.. Thank YOU
Re: Apply Rotation to a set of cords
But how to rotate object around the edge? mission impossible at FreeCAD?
Thanks
Darek
github.com/dprojects
workbench for woodworking is available at: github.com/dprojects/Woodworking
Re: Apply Rotation to a set of cords
Peivably using Placement specification with:
Code: Select all
Placement(VT, rot, c_rot)
VT = translation vector
rot = rotation specification
c_rot = center if rotation
It usually work as it is specified also in the wiki page.
Regards
Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/