How to make each irregular polyhedron randomly generated in makeCloud different?

Asked by weijie on 2020-05-20

Dear all,

I used the polyhedra_utils.polyhedra function to create irregular polyhedrons. How to make each irregular polyhedron different in the makeCloud space?

Below is my MWS:

Thanks in advance.
Jie

########################
from yade import polyhedra_utils,pack,plot,utils,qt
import random
import numpy as np

#-------------------------------------------
#Material
n = PolyhedraMat(young=7.2e7,poisson=.2,density=2.5e3)

#-------------------------------------------
#Dimensions

meanSize = 0.05
wallThickness = 0.5*meanSize
distanceToCentre = 0.01
lengthOfBase = 0.250
heightOfBase = 0.600

#-------------------------------------------
#Make Cloud

sp=pack.SpherePack()
mn,mx=Vector3(-0.5*(lengthOfBase-wallThickness),0.5*meanSize,-0.5*(lengthOfBase-wallThickness)),Vector3(0.5*(lengthOfBase-wallThickness),0.5*heightOfBase,0.5*(lengthOfBase-wallThickness))
R=sqrt(3.0)*distanceToCentre
sp.makeCloud(mn,mx,R,0,-1,False)

for s in sp:
    b=Body()
    b.mask=1
    color=Vector3(random.random(),random.random(),random.random())
    b=polyhedra_utils.polyhedra(material=n,size=(2*distanceToCentre,distanceToCentre,distanceToCentre),seed=5,color=color)
    b.state.pos = s[0] #s[0] stores center
    b.state.ori = Quaternion((random.random(),random.random(),random.random()),random.random()) #s[2]
    O.bodies.append(b)

from yade import qt
v=qt.View()
O.saveTmp()

Question information

Language:
English Edit question
Status:
Solved
For:
Yade Edit question
Assignee:
No assignee Edit question
Solved by:
Jan Stránský
Solved:
2020-05-21
Last query:
2020-05-21
Last reply:
2020-05-20
Best Jan Stránský (honzik) said : #1

Hello,

> b=polyhedra_utils.polyhedra(...,seed=5,...)

use different seed, e.g.
###
for i,s in enumerate(sp):
   ...
   b=polyhedra_utils.polyhedra(...,seed=i+1,...)
###

or do not set seed at all.

cheers
Jan

weijie (amandajoe) said : #2

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