# 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. If I input a orientation out of the range ,let's say, a.state.

Thanks a lot !

## Question information

- Language:
- English Edit question

- Status:
- Solved

- For:
- Yade Edit question

- Assignee:
- No assignee Edit question

- Solved by:
- Jan Stránský

- Solved:
- 2019-12-20

- Last query:
- 2019-12-20

- Last reply:
- 2019-12-20

Jérôme Duriez (jduriez) said : | #1 |

Hi

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

I would disagree with that, and Wikipedia does the same: https:/

As for your 2., a.state.

a.state.ori = ((10,10,10),10) # a a Body

would work on the other hand

Jan Stránský (honzik) said : | #2 |

Hello,

(apart from what Jerome already wrote)

1) x,y,z,w can be any number in general.

x**2+y*

> 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.

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

> a.state.

the easiest way is to try yourself :-)

a.state.

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 : | #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 : | #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(

Then yes, choosing the AXIS COMPONENTS x,y,z randomly from range (-1,1) and ANGLE from range (0,2*pi)

axis = [random.

angle = random.

b.state.ori = Quaternion(

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

[1] https:/

socc (socc) said : | #5 |

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