# Defining complex geometries using trimesh#

Tidy3D offers four primitive geometric shapes: Box, Cylinder, Sphere, and PolySlab. An extensive array of intricate geometrical configurations can be defined from these fundamental building blocks by manipulating their properties and hierarchical arrangements. For instance, our tutorials on the Luneburg lens waveguide size converter and the Fresnel lens showcase the creation of curved surfaces through the strategic layering of cylindrical elements.

Beyond the in-built primitives, Tidy3D accommodates external geometrical specifications in either the gds or stl file formats, allowing users to import custom geometries created in their preferred design tools. Additionally, compatibility with external libraries like gdstk and shapely opens the gateway to even more complex geometric possibilities. Using gdstk to create various waveguide structures has been demonstrated in various examples such as the polarization splitter and rotator based on 90 degree bends.

In this tutorial, weβll introduce an alternative avenue for crafting complex geometries using the trimesh library. Through examples featuring a torus and an ellipsoid, weβll guide you through the process of defining a mesh structure that is directly usable in Tidy3D simulations.

Remember to install Tidy3D as pip install "tidy3d[trimesh]", which will install optional dependencies needed for processing surface meshes.

[1]:

import tidy3d as td
import trimesh
import numpy as np
import matplotlib.pyplot as plt


## Built-in Geometries#

First off all, trimesh provides some built-in geometries such as ring (annulus), box, capsule, cone, cylinder, and so on. Letβs create a ring as an example.

After the mesh is created, we can visualize the mesh in 3D.

[2]:

n_sections = 100 # how many sections to discretize the mesh

# create a ring mesh
ring_mesh = trimesh.creation.annulus(r_min=9, r_max=10, height=1, sections=n_sections)

# plot the mesh
ring_mesh.show()

[2]: