Discussion:
[deprecated list] Quaternion question
Anton Gladky
2009-05-06 12:04:46 UTC
Permalink
Hello all!

I have a quaternion question.
I have two of them:
Q1 (0, 0, 1, PI/4) (around axis OZ)
Q1 (0, 1, 0, PI/6) (around axis OY)
My box should be rotated using first quaternion, and the a second one. It is
a new topic for me. Can anybody advice me, what should I do to solve this
task?


Best Regards / Mit freundlichen GrÌßen / С МаОлучшОЌО пПжелаМОяЌО

Anton Gladkyy
Sergei D.
2009-05-06 13:34:24 UTC
Permalink
Post by Anton Gladky
Hello all!
I have a quaternion question.
Q1 (0, 0, 1, PI/4) (around axis OZ)
Q1 (0, 1, 0, PI/6) (around axis OY)
My box should be rotated using first quaternion, and the a second one. It is
a new topic for me. Can anybody advice me, what should I do to solve this
task?
You can product them:
if M - first rotation and Q - second rotation, then final rotation R is
R = Q*M = (q0+q)*(m0+m) = q0 m0 - q Dot m + q0 m + m0 q + q Cross m,
where q and m is the vector part of quaternions; q0 and m0 is the its
scalar part.

I don't know if there is quaternion product from python in YADE
(Vaclav?), but from c++ it is simply as:

Quaternion3r Q,M,R;
R = Q*M;

ps. Also you can see formulas and references in Appendix of my PhD
thesis (in russian): http://dl.getdropbox.com/u/714488/DorofeenkoPhD.pdf




_______________________________________________
Mailing list: https://launchpad.net/~yade-users
Post to : yade-***@lists.launchpad.net
Unsubscribe : https://launchpad.net/~yade-users
More help : https://help.launchpad.net/ListHelp
Václav Šmilauer
2009-05-06 20:29:26 UTC
Permalink
Post by Sergei D.
I don't know if there is quaternion product from python in YADE
(Vaclav?)
(Currently) Quaternions are converted to plain 4-list of floats
(axis,angle) if requested from python, no special type.

If want to play with Quaternions in python, I recommend very simple
euclid module: http://partiallydisassembled.net/euclid.html

Vaclav



_______________________________________________
Mailing list: https://launchpad.net/~yade-users
Post to : yade-users-oU9gvf+***@public.gmane.org
Unsubscribe : https://launchpad.net/~yade-users
More help : https://help.launchpad.net/ListHelp
Sergei D.
2009-05-07 06:59:53 UTC
Permalink
Post by Václav Šmilauer
If want to play with Quaternions in python, I recommend very simple
euclid module: http://partiallydisassembled.net/euclid.html
Vaclav
Anton, I have attached modified scene.xml, which I have get from your
scene.xml
with Vaclav's euclid.py (Vaclav, thanks!) and typing the follow commands
in YADE console:

from euclid import *
O.load('scene.xml')

q1 = Quaternion.new_rotate_axis(pi/6, Vector3(0,1,0)) # rotate about Y
on pi/6 angles
q2 = Quaternion.new_rotate_axis(pi/2, Vector3(0,0,1)) # rotate about Z
on pi/2 angles

# now, YADE's se3 is [X,Y,Z, Ax,Ay,Az, a]
# where X,Y,Z is the body's position;
# Ax,Ay,Az is the rotation axis,
# a is the rotation angle.
# So, we...
o1 = q1.get_angle_axis() # get angle and axis for the first blue box
(rotation about Y)
o2 = (q2*q1).get_angle_axis() # get angle and axis for the second blue
box (first rotation about Y, after this rotation aboud Z)
# Then, we set the parameters,
O.bodies[1].phys['se3'] = [0,0,0, o1[1][0], o1[1][1], o1[1][2], o1[0]]
O.bodies[3].phys['se3'] = [0,0,0, o2[1][0], o2[1][1], o2[1][2], o2[0]]
Anton Gladky
2009-05-11 10:56:55 UTC
Permalink
THANK YOU ALL for the help!
It helped me a lot, I've found my mistake. Your advices helped me to create
such objects:
Loading Image...
Loading Image...

After that I'm getting "quaternion expert" :)

Actually I used another library
http://www.sacredsoftware.net/tutorials/Tutorials.xhtml for creating
quaternion. Also I would recommend this tutorials for understanding this
complicated topic. Maybe it is a good idea to add this link to wiki?

Thanks again


Best Regards / Mit freundlichen GrÌßen / С МаОлучшОЌО пПжелаМОяЌО

Anton Gladkyy
Post by Sergei D.
Post by Václav Šmilauer
If want to play with Quaternions in python, I recommend very simple
euclid module: http://partiallydisassembled.net/euclid.html
Vaclav
Anton, I have attached modified scene.xml, which I have get from your
scene.xml
with Vaclav's euclid.py (Vaclav, thanks!) and typing the follow commands
from euclid import *
O.load('scene.xml')
q1 = Quaternion.new_rotate_axis(pi/6, Vector3(0,1,0)) # rotate about Y
on pi/6 angles
q2 = Quaternion.new_rotate_axis(pi/2, Vector3(0,0,1)) # rotate about Z
on pi/2 angles
# now, YADE's se3 is [X,Y,Z, Ax,Ay,Az, a]
# where X,Y,Z is the body's position;
# Ax,Ay,Az is the rotation axis,
# a is the rotation angle.
# So, we...
o1 = q1.get_angle_axis() # get angle and axis for the first blue box
(rotation about Y)
o2 = (q2*q1).get_angle_axis() # get angle and axis for the second blue
box (first rotation about Y, after this rotation aboud Z)
# Then, we set the parameters,
O.bodies[1].phys['se3'] = [0,0,0, o1[1][0], o1[1][1], o1[1][2], o1[0]]
O.bodies[3].phys['se3'] = [0,0,0, o2[1][0], o2[1][1], o2[1][2], o2[0]]
_______________________________________________
Mailing list: https://launchpad.net/~yade-users<https://launchpad.net/%7Eyade-users>
Unsubscribe : https://launchpad.net/~yade-users<https://launchpad.net/%7Eyade-users>
More help : https://help.launchpad.net/ListHelp
Sergei D.
2009-05-06 13:30:34 UTC
Permalink
Post by Anton Gladky
Hello all!
I have a quaternion question.
Q1 (0, 0, 1, PI/4) (around axis OZ)
Q1 (0, 1, 0, PI/6) (around axis OY)
My box should be rotated using first quaternion, and the a second one. It is
a new topic for me. Can anybody advice me, what should I do to solve this
task?
You can product them:
if M - first rotation and Q - second rotation, then final rotation R is
R = Q*M = (q0+q)*(m0+m) = q0 m0 - q Dot m + q0 m + m0 q + q Cross m,
where q and m is the vector part of quaternions; q0 and m0 is the its
scalar part.

I don't know if there is quaternion product from python in YADE
(Vaclav?), but from c++ it is simply as:

Quaternion3r Q,M,R;
R = Q*M;

ps. Also you can see formulas and references in Appendix of my PhD
thesis (in russian): http://dl.getdropbox.com/u/714488/DorofeenkoPhD.pdf



_______________________________________________
Mailing list: https://launchpad.net/~yade-users
Post to : yade-***@lists.launchpad.net
Unsubscribe : https://launchpad.net/~yade-users
More help : https://help.launchpad.net/ListHelp
Anton Gladky
2009-05-06 14:48:43 UTC
Permalink
Thank you, Sergei!

I have also tried this way but with no success. Maybe I do not completely
understand quaternions.
I have attached the small XML file, what I generate. Yellow boxes are ok,
but blue ones needs to be rotated a little bit around its long axis.

Could you not give me an advice?

Best Regards / Mit freundlichen GrÌßen / С МаОлучшОЌО пПжелаМОяЌО

Anton Gladkyy
Post by Sergei D.
Post by Anton Gladky
Hello all!
I have a quaternion question.
Q1 (0, 0, 1, PI/4) (around axis OZ)
Q1 (0, 1, 0, PI/6) (around axis OY)
My box should be rotated using first quaternion, and the a second one. It
is
Post by Anton Gladky
a new topic for me. Can anybody advice me, what should I do to solve this
task?
if M - first rotation and Q - second rotation, then final rotation R is
R = Q*M = (q0+q)*(m0+m) = q0 m0 - q Dot m + q0 m + m0 q + q Cross m,
where q and m is the vector part of quaternions; q0 and m0 is the its
scalar part.
I don't know if there is quaternion product from python in YADE
Quaternion3r Q,M,R;
R = Q*M;
ps. Also you can see formulas and references in Appendix of my PhD
thesis (in russian): http://dl.getdropbox.com/u/714488/DorofeenkoPhD.pdf
Loading...