# The meaning of O.bodies.state.ori/refOri

Hi,

When I was trying to calculate the rotation angle of spheres, I found the following state parameters may be useful, but I didn't fully understand the meaning of each parameter.

For example, for one typical sphere, I got:

1.O.bodies[

#get current orientation

I got: Quaternion(

2.O.bodies[

# get reference orientation

I got: Quaternion(

How yade define the refOri for a particle? I suppose refOri will not change, am I right?

3.O.bodies[

#Rotation from reference orientation (as rotation vector)

I got: Vector3(

How can I use this vector to calculate the rotation angle? Is this vector related to ori and refOri?

4.O.bodies[

I got: Vector3(

Can the displacement of the sphere be calculated by O.state.

Thanks in advance

Have a good weekend

Leonard

https:/

## Question information

- Language:
- English Edit question

- Status:
- Solved

- For:
- Yade Edit question

- Assignee:
- No assignee Edit question

- Solved by:
- Jan Stránský

- Solved:
- 2020-07-26

- Last query:
- 2020-07-26

- Last reply:
- 2020-07-26

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

Hello,

1.

the quaternion is printed in its axis-angle representation. The orientation is represented as "rotation by the angle around the axis"

2.

Using "utils" particle creation method (e.g. utils.sphere, utils.box, ...), which I suppose, state.refOri is set as the initial value of state.ori

refOri does not change "automatically", but you can change it "manually" if you like.

3.

see the source code [1]. it is angle equivalent of state.displ() [2], i.e. rotation "between" state.refOri and state.ori.

The vector i axis*angle

However, there is a problem for "large rotations", e.g. rolling of particles. Have a look at similar discussion [3] (from comment #14 on) if this your case

4.

yes. This is actually what state.displ() [2] does

cheers

Jan

[1] https:/

[2] https:/

[3] https:/

Leonard (z2521899293) said : | #2 |

Hi Jan,

Many thanks for your explanation.

>1,2,4 are all clear.

>for question 3 (O.bodies[

Since O.bodies[

BTW, one thing to confirm: is the angle obtained by O.bodies[

Thanks

Leonard

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

> How to calculate this incremental rotation angle?

see [3] for discussion (code below)

> ... radian or degree?

radian

cheers

Jan

###

b = facet((

O.bodies.append(b)

b.state.angVel = (0,0,.1)

rot = 0

ori = b.state.refOri

def updateRot(

relRot = ori.conjugate(

axis,angle = relRot.

if (axis[2]) < 0: # "negative" rotation ...

angle *= -1 # ... negate the positive angle

rot += angle # updates rotation angle

ori = b.state.ori # "store" new orientation value

return rot,ori

for i in range(20):

O.step()

rot,ori = updateRot(

print i,rot

b.state.angVel = (0,0,-.3)

for i in range(40):

O.step()

rot,ori = updateRot(

print i,rot

###

Leonard (z2521899293) said : | #4 |

Hi Jan,

Thanks for the MWE.

One stupid question:

what is the meaning of each components in the vector of State.rot()?

I am asking this because I notice that "updateRot(

My stupid guess as something like:

if (axis[0]) < 0 or (axis[1]) < 0 or (axis[2]) < 0:

angle *= -1

.....

Many thanks

Leonard

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

Ok, the code was meant for the example in the other question related specifically to z axis. General case below.

"rot" is rotation vector, you can convert it back to quaternion with

##

angle = rot.norm()

axis = rot.normalized()

ori = Quaternion(

##

cheers

Jan

###

b = facet((

O.bodies.append(b)

rot = Vector3.Zero # total rotation Vector

ori = b.state.refOri # last known orientation

def updateRot(

relOri = ori.conjugate(

axis,angle = relOri.

relRot = axis*angle # relative rotation vector

rot += relRot # updates rotation vector

ori = b.state.ori # "store" new orientation value

return rot,ori

b.state.angVel = (0,0,.1)

for i in range(20):

O.step()

rot,ori = updateRot(

print i,rot

b.state.angVel = (0,0,-.3)

for i in range(40):

O.step()

rot,ori = updateRot(

print i,rot

b.state.angVel = (.1,0,0)

for i in range(20):

O.step()

rot,ori = updateRot(

print i,rot

###

Leonard (z2521899293) said : | #6 |

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