# How to generate a regular dodecahedron in polyhedra_utils module？

Dear all,

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

Jie

## Question information

Language:
English Edit question
Status:
Solved
For:
Assignee:
No assignee Edit question
Solved by:
Vasileios Angelidakis
Solved:
2020-05-06
Last query:
2020-05-06
2020-05-05
 Vasileios Angelidakis (vsangelidakis) said on 2020-05-04: #1

Hi Jie,

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

Hope this helps,
Vasileios

 weijie (amandajoe) said on 2020-05-05: #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：
################################
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)

v=qt.View()
########################

Best regards,
Jie Vasileios Angelidakis (vsangelidakis) said on 2020-05-05: #3

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.

- 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

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)