How to generate a regular dodecahedron in polyhedra_utils module?

Asked by weijie on 2020-05-04

Dear all,

Is there a way to generate regular dodecahedron in polyhedra_utils module?

Thanks in advance.
Jie

Question information

Language:
English Edit question
Status:
Solved
For:
Yade Edit question
Assignee:
No assignee Edit question
Solved by:
Vasileios Angelidakis
Solved:
2020-05-06
Last query:
2020-05-06
Last reply:
2020-05-05

Hi Jie,

Currently there does not exist a specific function to do this.
Yet, you can calculate the vertices of a dodecahedron easily, following [1] and scale it accordingly to the particle size you want.

Hope this helps,
Vasileios

[1] https://en.wikipedia.org/wiki/Regular_dodecahedron#Cartesian_coordinates

weijie (amandajoe) said : #2

Hi Vasileios, and thank you again.

I created the dodecahedron according to the reference, but I encountered difficulties in scaling. In my code below, when d = 1, it is the regular dodecahedron in the reference, and its edge length is √5 − 1. When the edge length of the regular dodecahedron I want to create is 9, how should the coordinates change?
Following is my code:
################################
from yade import polyhedra_utils,pack,plot,utils,export,qt,ymport
import numpy as np
import math
import random
n = PolyhedraMat(young=7.2e7,poisson=.2,density=2.5e3)
O.materials.append(n)
a=(1+math.sqrt(5))/2
d=1
v1=(d,d,d),(d,d,-d),(d,-d,d),(d,-d,-d),(-d,d,d),(-d,d,-d),(-d,-d,d),(-d,-d,-d)
v2=(0,a,1/a),(0,a,-1/a),(0,-a,1/a),(0,-a,-1/a)
v3=(1/a,0,a),(1/a,0,-a),(-1/a,0,a),(-1/a,0,-a)
v4=(a,1/a,0),(a,-1/a,0),(-a,1/a,0),(-a,-1/a,0)
v=((d,d,d),(d,d,-d),(d,-d,d),(d,-d,-d),(-d,d,d),(-d,d,-d),(-d,-d,d),(-d,-d,-d),(0,a,1/a),(0,a,-1/a),(0,-a,1/a),(0,-a,-1/a),(1/a,0,a),(1/a,0,-a),(-1/a,0,a),(-1/a,0,-a),(a,1/a,0),(a,-1/a,0),(-a,1/a,0),(-a,-1/a,0))
#print(v)
b = polyhedra_utils.polyhedra(material=n,v=v,fixed=True,color=(0,0,120))
O.bodies.append(b)

from yade import qt
v=qt.View()
v.sceneRadius=10.0
########################

Best regards,
Jie

Hi Jie,

You define the vertices in a tuple of tuples ((x,y,z), ...). Tuples and lists in Python do not allow you to multiply each element with a scalar. On the other hand, Vector3 (from the Eigen library) and array (from numpy) allow you to do this. So, I created your vertices as an array of Vector3 elements. Then, the scale factor you want, is SF=newEdge/oldEdge.

Some advice:
- Use color=[0,0,1] to get a blue particle. Values over 1 inside the color will mess up shading :)
- I activated the grid for you, so you can inspect the particle size yourself (with v.ortho=True). You can modify the density of the grid with the plus-minus keys.

Best Regards,
Vasileios

from yade import polyhedra_utils,pack,plot,utils,export,qt,ymport
import numpy as np
import math
import random

n = PolyhedraMat(young=7.2e7,poisson=.2,density=2.5e3)
O.materials.append(n)
a=(1+math.sqrt(5))/2
d=1
v1=(d,d,d),(d,d,-d),(d,-d,d),(d,-d,-d),(-d,d,d),(-d,d,-d),(-d,-d,d),(-d,-d,-d)
v2=(0,a,1/a),(0,a,-1/a),(0,-a,1/a),(0,-a,-1/a)
v3=(1/a,0,a),(1/a,0,-a),(-1/a,0,a),(-1/a,0,-a)
v4=(a,1/a,0),(a,-1/a,0),(-a,1/a,0),(-a,-1/a,0)
v=((d,d,d),(d,d,-d),(d,-d,d),(d,-d,-d),(-d,d,d),(-d,d,-d),(-d,-d,d),(-d,-d,-d),(0,a,1/a),(0,a,-1/a),(0,-a,1/a),(0,-a,-1/a),(1/a,0,a),(1/a,0,-a),(-1/a,0,a),(-1/a,0,-a),(a,1/a,0),(a,-1/a,0),(-a,1/a,0),(-a,-1/a,0))
#print(v)

vertices=[]
for ver in v:
 vertices.append(Vector3(ver))
vertices=np.array(vertices)

oldEdge=sqrt(5)-1
newEdge=9
SF=newEdge/oldEdge
vertices=vertices*SF

b = polyhedra_utils.polyhedra(material=n,v=vertices,fixed=True,color=(0,0,1))
O.bodies.append(b)

from yade import qt
v=qt.View()
v.sceneRadius=30.0
v.grid=(True, True, True)
v.ortho=True

weijie (amandajoe) said : #4

Thanks Vasileios Angelidakis, that solved my question.