← Back to team overview

yade-users team mailing list archive

Re: [Question #692057]: The meaning of O.bodies.state.ori/refOri

 

Question #692057 on Yade changed:
https://answers.launchpad.net/yade/+question/692057

    Status: Open => Answered

Jan Stránský proposed the following answer:
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(axis,angle)
##

cheers
Jan

###
b = facet(((0,0,0),(1,0,0),(0,1,0)))
O.bodies.append(b)

rot = Vector3.Zero # total rotation Vector
ori = b.state.refOri # last known orientation

def updateRot(b,rot,ori):
   relOri = ori.conjugate()*b.state.ori # same as State.rot(), https://gitlab.com/yade-dev/trunk/-/blob/master/core/State.hpp#L40
   axis,angle = relOri.toAxisAngle() # get axis and angle from quaternion
   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(b,rot,ori)
   print i,rot

b.state.angVel = (0,0,-.3)
for i in range(40):
   O.step()
   rot,ori = updateRot(b,rot,ori)
   print i,rot

b.state.angVel = (.1,0,0)
for i in range(20):
   O.step()
   rot,ori = updateRot(b,rot,ori)
   print i,rot
###

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