Question #658629 on Yade changed: https://answers.launchpad.net/yade/+question/658629
Jan Stránský proposed the following answer: ### def cylSurf(center,radius,height,nSegments=12,thick=0,**kw): """creates cylinder made of boxes. Axis is parallel with z+ center ... center of bottom disc radius ... radius of cylinder height ... height of cylinder nSegments ... number of boxes forming cylinder thick ... thickness of the boxes **kw ... keywords passed to box function (e.g. material, color ...) """ # just converts (a,b,c) to Vector3(a,b,c) to enable "center + ..." center = Vector3(center) # nSegments angles to define individual boxes, from 0 to 2*pi angles = [i*2*pi/nSegments for i in range(nSegments)] # centers of boxes. Vector 3(radius,0,0) rotated by angle 'a' # z coordinate is .5*height # center + shift = center of corresponding box pts = [center + Vector3(radius*cos(a),radius*sin(a),.5*height) for a in angles] # centers of plates ret = [] for i,pt in enumerate(pts): # for each box center create corresponding box # "length" of the box along circumference, cylinder circumference / nSegments l = pi*radius/nSegments # extents, half dimensions along x,y,z axis es = (.5*thick,l,.5*height) # by default box is axis-aligned, we need to rotate it along z axis (0,0,1) by angle i*2*pi/nSegments ori = Quaternion((0,0,1),i*2*pi/nSegments) # have a look at utils.box documentation. pt=center of box, es=extents (half dimension), ori=orientation ret.append(box(pt,es,ori,**kw)) return ret ### you can use print to see the values if you want to understand what is going on. You can also write your function from the scratch. cheers Jan -- You received this question notification because your team yade-users is an answer contact for Yade. _______________________________________________ Mailing list: https://launchpad.net/~yade-users Post to : yade-users@lists.launchpad.net Unsubscribe : https://launchpad.net/~yade-users More help : https://help.launchpad.net/ListHelp