How does the orientation of particle work in YADE?

Hey,

I read about the orientation of particle from the document but the description is not explicit.
It says that the orientation is represented by a quaternion, which could be denoted as ((x, y, z)，w). But how is each component defined?
1. In mathematics, each of the component of the quaternion ranges from -1 to 1, and x**2+y**2+z**2+w**2=1. Is that true in YADE? is the w component a radians or a real number?
2. If I input a orientation out of the range ,let's say, a.state.orientation=(10,10,10,10),how will the code responds?

Thanks a lot !

Question information

Language:
English Edit question
Status:
Solved
For:
Assignee:
No assignee Edit question
Solved by:
Jan Stránský
Solved:
2019-12-20
Last query:
2019-12-20
2019-12-20
 Jérôme Duriez (jduriez) said on 2019-12-20: #1

Hi

> 1. In mathematics, each of the component of the quaternion ranges from -1 to 1, and x**2+y**2+z**2+w**2=1

I would disagree with that, and Wikipedia does the same: https://en.wikipedia.org/wiki/Quaternion#Definition

As for your 2., a.state.orientation=(10,10,10,10) will first of all return an error since you did not follow the "((x, y, z)，w)" syntax: parentheses to define the vector part (x,y,z) are missing in your command

a.state.ori = ((10,10,10),10) # a a Body
would work on the other hand

 Jan Stránský (honzik) said on 2019-12-20: #2

Hello,

(apart from what Jerome already wrote)

1) x,y,z,w can be any number in general.
x**2+y**2+z**2+w**2=1 hold for **unit** quaternions (which Yade uses)

> is the w component a radians or a real number?

is there a difference?
w is internally a real number, you can access the internals as a.state.ori[0], a.state.ori[1], a.state.ori[2], a.state.ori [3] (have a look on Eigen / minieigen documentation which index correspond to x,y,z,w, I think (but I am not sure and don't want to search it right now) that the order is not x,y,z,w

> a.state.orientation=...

a.state.ori is the attribute (not orientation)

> a.state.orientation=(10,10,10,10),how will the code responds?

the easiest way is to try yourself :-)
a.state.ori=(10,10,10,10) # error, as Jerome pointed
a.state.ori = (10,10,10),10 # ok, 1st argument is axis, 2nd is angle
print(a.state.ori) # you get axis-angle representation, not x,y,z,w directly, see above

cheers
Jan

 socc (socc) said on 2019-12-20: #3

Thanks a lot

I am just trying to confirm that I understand this parameter correctly.
(x,y,z) is the rotation axis, and w is the rotation angle but is expressed as a radians.
By letting x,y and z subject to a random uniform distribution, lets' say ranging from (-1,1) and making w range from 0 to 2*pi, I can go through almost every orientation of this particle. Am I correct?

 Jan Stránský (honzik) said on 2019-12-20: #4

Hi,

1) you are interested in the math behind, really in the stored internal values x,y,z,w.
Internal values x,y,z,w are NOT directly axis and angle (although x,y,z,w and axis-angle can be computed one from the other).
So the random distribution you proposed would not lead to sensible results.

2) you are interested from "user point of view"
Then you do not need to bother with the internal values x,y,z,w at all.
All you need is to know that quaternion can be represented as axis-angle pair. This is how you create quaternion in Yade
b.state.ori = (1,2,3),pi # axis = Vector3(1,2,3), angle = pi
and how they are printed
print(b.state.ori) # Quaternion(axis,angle)

Then yes, choosing the AXIS COMPONENTS x,y,z randomly from range (-1,1) and ANGLE from range (0,2*pi)
axis = [random.uniform(-1,1) for _ in range(3)]
angle = random.uniform(0,2*pi)
b.state.ori = Quaternion(axis,angle)
can generate any possible orientation.

I am not sure with the distribution, have a look at [1] and further referenced materials if you require uniform distribution.

cheers
Jan

 socc (socc) said on 2019-12-20: #5

Thanks Jan Stránský, that solved my question.