New question #449020 on Yade:
https://answers.launchpad.net/yade/+question/449020

I'm trying to output some data from clumps for use in an external program 
(SolidWorks), and I've not been able to reproduce the orientation of the clumps 
in YADE.

As a bit of background, I've seen that the quaternion can be converted into an 
axis-angle representation, according to this document: 
http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.468.5407&rep=rep1&type=pdf

I've noticed during testing that the following code produces unexpected results:

```
from yade import qt
import numpy as np

def clamp (val, minval, maxval):
    if val < minval: return minval
    if val > maxval: return maxval
    return val

O.bodies.append(sphere([0,0,0],0.2,fixed=True,wire=True))       #Reference 
Sphere
sphId = O.bodies.append(sphere([0,0,0],0.2,fixed=False,wire=True)) #Rotating 
Sphere

arccos = np.arccos

def Rotate():
        global O,clumpId,pi,sphId
        #O.forces.addRot(sphId,Vector3(pi/10,0,0)) #Rotate about x
        O.forces.addRot(sphId,Vector3(0,pi/10,0)) #Rotate about y
        #O.forces.addRot(sphId,Vector3(0,0,pi/10)) #Rotate about z

O.engines=[
        ForceResetter(),
        PyRunner(iterPeriod=1,command='Rotate()'),
        NewtonIntegrator()
]

O.step()
for i in xrange(0,10):
        q = O.bodies[sphId].state.ori.normalized()
        ang = 2*arccos(clamp(q[0],-1,1))
        print('\t%g\t%g\t%g\t%g'%(ang,q[1],q[2],q[3]))
        O.step()
```

It prints the expected angle to rotate with and the vector to rotate about. I 
would expect that for each of the cases (x,y,and z), it would just change the 
angle (1st output) and the second three outputs would be the constant i,j, and 
k unit vectors respectively.

When rotationg about the x axis, that appears to be the case, as this is the 
output:

3.14159 0       0       1
2.82743 0       0       0.987688
2.51327 0       0       0.951057
2.19911 0       0       0.891007
1.88496 0       0       0.809017
1.5708  0       0       0.707107
1.25664 0       0       0.587785
0.942478        0       0       0.45399
0.628319        0       0       0.309017
0.314159        0       0       0.156434

But rotating about the other two axes does not produce the same results:

Rotate about y axis:

3.14159 0       0       1
3.14159 0.156434        0       0.987688
3.14159 0.309017        0       0.951057
3.14159 0.45399 0       0.891007
3.14159 0.587785        0       0.809017
3.14159 0.707107        0       0.707107
3.14159 0.809017        0       0.587785
3.14159 0.891007        0       0.45399
3.14159 0.951057        0       0.309017
3.14159 0.987688        0       0.156434


Rotate about z axis:

3.14159 0       0       1
3.14159 0       0.156434        0.987688
3.14159 0       0.309017        0.951057
3.14159 0       0.45399 0.891007
3.14159 0       0.587785        0.809017
3.14159 0       0.707107        0.707107
3.14159 0       0.809017        0.587785
3.14159 0       0.891007        0.45399
3.14159 0       0.951057        0.309017
3.14159 0       0.987688        0.156434

What is going on here? If I'm rotating a sphere from a default orientation 
about a principal axis, shouldn't the last three outputs on each line be the 
unit vector of the axis, as is the case with the x-axis?

Also, why does the default quaternion include a rotation of pi about the z axis?

Regardless of whether this is a bug or something wrong with my understanding, 
can someone help me figure out a workaround so I can obtain a useful axis-angle 
representation of a sphere or clump?

-- 
You received this question notification because your team yade-users is
an answer contact for Yade.

_______________________________________________
Mailing list: https://launchpad.net/~yade-users
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~yade-users
More help   : https://help.launchpad.net/ListHelp

Reply via email to