Goal of this notebook:
A 3D cubic lattice is defined by 3 vectors orthognal vectors. In the simplest case, these are $(\vec{u}_x, \vec{u}_y, \vec{u}_z)$. This can be implemented using pyvista
.
import pyvista as pv
def make_lattice(Nx=4, Ny=4, Nz=3, radius=0.3):
"""Creates a cubical lattice of spheres."""
lattice = []
offset_x = 0
offset_y = 0
offset_z = 0
for i in range(Nx):
for j in range(Ny):
for k in range(Nz):
sphere = pv.Sphere(radius=radius, center=(i - offset_x, j - offset_y, k - offset_z))
lattice.append(sphere)
return lattice
lattice = make_lattice()
Let's plot this interactively.
Let's display the spheres.
Let's show some specific vectors within the lattice.
base_arrows = [pv.Arrow(direction=(1, 0, 0)),
pv.Arrow(direction=(0, 1, 0)),
pv.Arrow(direction=(0, 0, 1))]
pl = pv.PlotterITK()
for obj in lattice:
pl.add_mesh(obj)
for obj in base_arrows:
pl.add_mesh(obj, color='red')
pl.show()
Viewer(geometries=[{'vtkClass': 'vtkPolyData', 'points': {'vtkClass': 'vtkPoints', 'name': '_points', 'numberO…
pl = pv.PlotterITK()
for obj in lattice:
pl.add_mesh(obj)
pl.show()
Viewer(geometries=[{'vtkClass': 'vtkPolyData', 'points': {'vtkClass': 'vtkPoints', 'name': '_points', 'numberO…
box = pv.Box()
rotated_box = box.copy()
rotated_box.rotate_x(45)
rotated_box.rotate_z(45)
pl = pv.PlotterITK()
for obj in lattice + base_arrows:
pl.add_mesh(obj, opacity=0.3)
#pl.add_mesh(rotated_box, opacity=0.7, color='red')
pl.add_mesh(pv.Arrow(direction=(1, 1, 1)), color='blue')
pl.show()
Viewer(geometries=[{'vtkClass': 'vtkPolyData', 'points': {'vtkClass': 'vtkPoints', 'name': '_points', 'numberO…
pl = pv.PlotterITK()
for obj in lattice:
pl.add_mesh(obj)
#pl.add_mesh(rotated_box, opacity=0.7, color='red')
pl.add_mesh(pv.Arrow(direction=(1, 1, 1)), color='blue')
pl.show()
Viewer(geometries=[{'vtkClass': 'vtkPolyData', 'points': {'vtkClass': 'vtkPoints', 'name': '_points', 'numberO…
mesh = lattice[0]
for other in lattice[1:]:
mesh = mesh.merge(other)
mesh.save('lattice.vtk')