← Back to team overview

yade-users team mailing list archive

Re: [Question #696243]: Rotate cylinder

 

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

    Status: Open => Answered

Jan Stránský proposed the following answer:
Hello,

> Here is my code:

most of the code is irrelevant to the problem.
Please try to create a MWE [1], M = minimal (unnecessary code removed, focusing on the problem)
Your "initial" code would be just fine (with "Diamater" variable defined), showing the entire problem ("I intended to rotate these bodies, but they are not rotated")
The rest just scares/discourages potential helpers :-)


state.rot is a method to get relative rotation from initial rotation [1], something like state.displ().
With your code, you just overwritten the method to the (0,90,0) tuple, try this:
###
Diameter = 0.0079 #79 micrometer
cyl1 =geom.facetCylinder((0,-0.15,0),8*Diameter,0.07,Quaternion((0,0,1),.5*pi),24,wallMask=4)
cyl1 = [f for f in cyl1 if f.state.pos[0] < 0] # "half-cylinder"
cyl1=O.bodies.append(cyl1)

for j in cyl1:
    body= O.bodies[j]
    print(body.state.rot) # <bound method State.rot ...
    body.state.rot=(0,90,0)
    print(body.state.rot) # (0,90,0)
###

Just a note, in Yade the angles are rarely (if at all) in degrees..

To rotate a body, you have to modify state.ori. If the center of rotation is not state.pos, you have to modify state.pos as well:
###
Diameter = 0.0079 #79 micrometer
cyl1 =geom.facetCylinder((0,-0.15,0),8*Diameter,0.07,Quaternion((0,0,1),.5*pi),24,wallMask=4)
cyl1 = [f for f in cyl1 if f.state.pos[0] < 0] # "half-cylinder"
cyl1=O.bodies.append(cyl1)

rot = Quaternion((0,0,1),.5*pi) # 90 degrees around z axis
center = Vector3(0,0,0) # center of rotation

for j in cyl1:
    body= O.bodies[j]
    # change rotation
    body.state.ori *= rot
    # shift the body
    p = body.state.pos - center # relative vector from center to pos
    p = rot * p # rotated relative vector
    body.state.pos = center + p # new pos
###

cheers
Jan

[1] https://yade-dem.org/doc/yade.wrapper.html#yade.wrapper.State.rot

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