tidy3d.Geometry#
- class Geometry[source]#
Bases:
Tidy3dBaseModel
,ABC
Abstract base class, defines where something exists in space.
Attributes
Returns
Box
representation of the bounding box of aGeometry
.Returns bounding box min and max coordinates.
Default parameters for plotting a Geometry object.
A list of axes along which the
Geometry
is zero-sized based on its bounds.Methods
add_ax_labels_lims
(axis,Β ax[,Β buffer])Sets the x,y labels based on
axis
and the extends based onself.bounds
.bounds_intersection
(bounds1,Β bounds2)Return the bounds that are the intersection of two bounds.
car_2_sph
(x,Β y,Β z)Convert Cartesian to spherical coordinates.
car_2_sph_field
(f_x,Β f_y,Β f_z,Β theta,Β phi)Convert vector field components in cartesian coordinates to spherical.
evaluate_inf_shape
(shape)Returns a copy of shape with inf vertices replaced by large numbers if polygon.
from_gds
(gds_cell,Β axis,Β slab_bounds,Β gds_layer)Import a
gdstk.Cell
or agdspy.Cell
and extrude it into a GeometryGroup.from_shapely
(shape,Β axis,Β slab_bounds[,Β ...])Convert a shapely primitive into a geometry instance by extrusion.
inside
(x,Β y,Β z)For input arrays
x
,y
,z
of arbitrary but identical shape, return an array with the same shape which isTrue
for every point in zip(x, y, z) that is inside the volume of theGeometry
, andFalse
otherwise.inside_meshgrid
(x,Β y,Β z)Perform
self.inside
on a set of sorted 1D coordinates.intersections_2dbox
(plane)Returns list of shapely geometries representing the intersections of the geometry with a 2D box.
intersections_plane
([x,Β y,Β z])Returns list of shapely geometries at plane specified by one non-None value of x,y,z.
intersections_tilted_plane
(normal,Β origin,Β to_2D)Return a list of shapely geometries at the plane specified by normal and origin.
intersects
(other)Returns
True
if twoGeometry
have intersecting .bounds.intersects_axis_position
(axis,Β position)Whether self intersects plane specified by a given position along a normal axis.
intersects_plane
([x,Β y,Β z])Whether self intersects plane specified by one non-None value of x,y,z.
kspace_2_sph
(ux,Β uy,Β axis)Convert normalized k-space coordinates to angles.
load_gds_vertices_gdspy
(gds_cell,Β gds_layer)Load polygon vertices from a
gdspy.Cell
.load_gds_vertices_gdstk
(gds_cell,Β gds_layer)Load polygon vertices from a
gdstk.Cell
.parse_xyz_kwargs
(**xyz)Turns x,y,z kwargs into index of the normal axis and position along that axis.
plot
([x,Β y,Β z,Β ax])Plot geometry cross section at single (x,y,z) coordinate.
plot_shape
(shape,Β plot_params,Β ax)Defines how a shape is plotted on a matplotlib axes.
pop_axis
(coord,Β axis)Separates coordinate at
axis
index from coordinates on the plane tangent toaxis
.reflect_points
(points,Β polar_axis,Β ...)Reflect a set of points in 3D at a plane passing through the coordinate origin defined and normal to a given axis defined in polar coordinates (theta, phi) w.r.t.
rotate_points
(points,Β axis,Β angle)Rotate a set of points in 3D.
rotated
(angle,Β axis)Return a rotated copy of this geometry.
scaled
([x,Β y,Β z])Return a scaled copy of this geometry.
sph_2_car
(r,Β theta,Β phi)Convert spherical to Cartesian coordinates.
sph_2_car_field
(f_r,Β f_theta,Β f_phi,Β theta,Β phi)Convert vector field components in spherical coordinates to cartesian.
surface_area
([bounds])Returns object's surface area with optional bounds.
to_gds
(cell[,Β x,Β y,Β z,Β gds_layer,Β gds_dtype])Append a Geometry object's planar slice to a .gds cell.
to_gds_file
(fname[,Β x,Β y,Β z,Β gds_layer,Β ...])Export a Geometry object's planar slice to a .gds file.
to_gdspy
([x,Β y,Β z,Β gds_layer,Β gds_dtype])Convert a Geometry object's planar slice to a .gds type polygon.
to_gdstk
([x,Β y,Β z,Β gds_layer,Β gds_dtype])Convert a Geometry object's planar slice to a .gds type polygon.
translated
(x,Β y,Β z)Return a translated copy of this geometry.
unpop_axis
(ax_coord,Β plane_coords,Β axis)Combine coordinate along axis with coordinates on the plane tangent to the axis.
volume
([bounds])Returns object's volume with optional bounds.
- property plot_params#
Default parameters for plotting a Geometry object.
- inside(x, y, z)[source]#
For input arrays
x
,y
,z
of arbitrary but identical shape, return an array with the same shape which isTrue
for every point in zip(x, y, z) that is inside the volume of theGeometry
, andFalse
otherwise.- Parameters:
x (np.ndarray[float]) β Array of point positions in x direction.
y (np.ndarray[float]) β Array of point positions in y direction.
z (np.ndarray[float]) β Array of point positions in z direction.
- Returns:
True
for every point that is inside the geometry.- Return type:
np.ndarray[bool]
- inside_meshgrid(x, y, z)[source]#
Perform
self.inside
on a set of sorted 1D coordinates. Applies meshgrid to the supplied coordinates before checking inside.- Parameters:
x (np.ndarray[float]) β 1D array of point positions in x direction.
y (np.ndarray[float]) β 1D array of point positions in y direction.
z (np.ndarray[float]) β 1D array of point positions in z direction.
- Returns:
Array with shape
(x.size, y.size, z.size)
, which isTrue
for every point that is inside the geometry.- Return type:
np.ndarray[bool]
- abstract intersections_tilted_plane(normal, origin, to_2D)[source]#
Return a list of shapely geometries at the plane specified by normal and origin.
- Parameters:
normal (Coordinate) β Vector defining the normal direction to the plane.
origin (Coordinate) β Vector defining the plane origin.
to_2D (MatrixReal4x4) β Transformation matrix to apply to resulting shapes.
- Returns:
List of 2D shapes that intersect plane. For more details refer to Shapelyβs Documentation.
- Return type:
List[shapely.geometry.base.BaseGeometry]
- intersections_plane(x=None, y=None, z=None)[source]#
Returns list of shapely geometries at plane specified by one non-None value of x,y,z.
- Parameters:
x (float = None) β Position of plane in x direction, only one of x,y,z can be specified to define plane.
y (float = None) β Position of plane in y direction, only one of x,y,z can be specified to define plane.
z (float = None) β Position of plane in z direction, only one of x,y,z can be specified to define plane.
- Returns:
List of 2D shapes that intersect plane. For more details refer to Shapelyβs Documentation.
- Return type:
List[shapely.geometry.base.BaseGeometry]
- intersections_2dbox(plane)[source]#
Returns list of shapely geometries representing the intersections of the geometry with a 2D box.
- Returns:
List of 2D shapes that intersect plane. For more details refer to Shapelyβs Documentation.
- Return type:
List[shapely.geometry.base.BaseGeometry]
- intersects(other)[source]#
Returns
True
if twoGeometry
have intersecting .bounds.- Parameters:
other (
Geometry
) β Geometry to check intersection with.- Returns:
Whether the rectangular bounding boxes of the two geometries intersect.
- Return type:
bool
- intersects_plane(x=None, y=None, z=None)[source]#
Whether self intersects plane specified by one non-None value of x,y,z.
- Parameters:
x (float = None) β Position of plane in x direction, only one of x,y,z can be specified to define plane.
y (float = None) β Position of plane in y direction, only one of x,y,z can be specified to define plane.
z (float = None) β Position of plane in z direction, only one of x,y,z can be specified to define plane.
- Returns:
Whether this geometry intersects the plane.
- Return type:
bool
- intersects_axis_position(axis, position)[source]#
Whether self intersects plane specified by a given position along a normal axis.
- Parameters:
axis (int = None) β Axis normal to the plane.
position (float = None) β Position of plane along the normal axis.
- Returns:
Whether this geometry intersects the plane.
- Return type:
bool
- abstract property bounds#
Returns bounding box min and max coordinates.
- Returns:
Min and max bounds packaged as
(minx, miny, minz), (maxx, maxy, maxz)
.- Return type:
Tuple[float, float, float], Tuple[float, float float]
- static bounds_intersection(bounds1, bounds2)[source]#
Return the bounds that are the intersection of two bounds.
- property bounding_box#
Returns
Box
representation of the bounding box of aGeometry
.- Returns:
Geometric object representing bounding box.
- Return type:
- plot(x=None, y=None, z=None, ax=None, **patch_kwargs)[source]#
Plot geometry cross section at single (x,y,z) coordinate.
- Parameters:
x (float = None) β Position of plane in x direction, only one of x,y,z can be specified to define plane.
y (float = None) β Position of plane in y direction, only one of x,y,z can be specified to define plane.
z (float = None) β Position of plane in z direction, only one of x,y,z can be specified to define plane.
ax (matplotlib.axes._subplots.Axes = None) β Matplotlib axes to plot on, if not specified, one is created.
**patch_kwargs β Optional keyword arguments passed to the matplotlib patch plotting of structure. For details on accepted values, refer to Matplotlibβs documentation.
- Returns:
The supplied or created matplotlib axes.
- Return type:
matplotlib.axes._subplots.Axes
- add_ax_labels_lims(axis, ax, buffer=0.3)[source]#
Sets the x,y labels based on
axis
and the extends based onself.bounds
.- Parameters:
axis (int) β Integer index into βxyzβ (0,1,2).
ax (matplotlib.axes._subplots.Axes) β Matplotlib axes to add labels and limits on.
buffer (float = 0.3) β Amount of space to place around the limits on the + and - sides.
- Returns:
The supplied or created matplotlib axes.
- Return type:
matplotlib.axes._subplots.Axes
- static evaluate_inf_shape(shape)[source]#
Returns a copy of shape with inf vertices replaced by large numbers if polygon.
- static pop_axis(coord, axis)[source]#
Separates coordinate at
axis
index from coordinates on the plane tangent toaxis
.- Parameters:
coord (Tuple[Any, Any, Any]) β Tuple of three values in original coordinate system.
axis (int) β Integer index into βxyzβ (0,1,2).
- Returns:
The input coordinates are separated into the one along the axis provided and the two on the planar coordinates, like
axis_coord, (planar_coord1, planar_coord2)
.- Return type:
Any, Tuple[Any, Any]
- static unpop_axis(ax_coord, plane_coords, axis)[source]#
Combine coordinate along axis with coordinates on the plane tangent to the axis.
- Parameters:
ax_coord (Any) β Value along axis direction.
plane_coords (Tuple[Any, Any]) β Values along ordered planar directions.
axis (int) β Integer index into βxyzβ (0,1,2).
- Returns:
The three values in the xyz coordinate system.
- Return type:
Tuple[Any, Any, Any]
- static parse_xyz_kwargs(**xyz)[source]#
Turns x,y,z kwargs into index of the normal axis and position along that axis.
- Parameters:
x (float = None) β Position of plane in x direction, only one of x,y,z can be specified to define plane.
y (float = None) β Position of plane in y direction, only one of x,y,z can be specified to define plane.
z (float = None) β Position of plane in z direction, only one of x,y,z can be specified to define plane.
- Returns:
Index into xyz axis (0,1,2) and position along that axis.
- Return type:
int, float
- static rotate_points(points, axis, angle)[source]#
Rotate a set of points in 3D.
- Parameters:
points (ArrayLike[float]) β Array of shape
(3, ...)
.axis (Coordinate) β Axis of rotation
angle (float) β Angle of rotation counter-clockwise around the axis (rad).
- reflect_points(points, polar_axis, angle_theta, angle_phi)[source]#
Reflect a set of points in 3D at a plane passing through the coordinate origin defined and normal to a given axis defined in polar coordinates (theta, phi) w.r.t. the
polar_axis
which can be 0, 1, or 2.- Parameters:
points (ArrayLike[float]) β Array of shape
(3, ...)
.polar_axis (Axis) β Cartesian axis w.r.t. which the normal axis angles are defined.
angle_theta (float) β Polar angle w.r.t. the polar axis.
angle_phi (float) β Azimuth angle around the polar axis.
- volume(bounds=None)[source]#
Returns objectβs volume with optional bounds.
- Parameters:
bounds (Tuple[Tuple[float, float, float], Tuple[float, float, float]] = None) β Min and max bounds packaged as
(minx, miny, minz), (maxx, maxy, maxz)
.- Returns:
Volume in um^3.
- Return type:
float
- surface_area(bounds=None)[source]#
Returns objectβs surface area with optional bounds.
- Parameters:
bounds (Tuple[Tuple[float, float, float], Tuple[float, float, float]] = None) β Min and max bounds packaged as
(minx, miny, minz), (maxx, maxy, maxz)
.- Returns:
Surface area in um^2.
- Return type:
float
- translated(x, y, z)[source]#
Return a translated copy of this geometry.
- Parameters:
x (float) β Translation along x.
y (float) β Translation along y.
z (float) β Translation along z.
- Returns:
Translated copy of this geometry.
- Return type:
- scaled(x=1.0, y=1.0, z=1.0)[source]#
Return a scaled copy of this geometry.
- Parameters:
x (float = 1.0) β Scaling factor along x.
y (float = 1.0) β Scaling factor along y.
z (float = 1.0) β Scaling factor along z.
- Returns:
Scaled copy of this geometry.
- Return type:
- rotated(angle, axis)[source]#
Return a rotated copy of this geometry.
- Parameters:
angle (float) β Rotation angle (in radians).
axis (Union[int, Tuple[float, float, float]]) β Axis of rotation: 0, 1, or 2 for x, y, and z, respectively, or a 3D vector.
- Returns:
Rotated copy of this geometry.
- Return type:
- static car_2_sph(x, y, z)[source]#
Convert Cartesian to spherical coordinates.
- Parameters:
x (float) β x coordinate relative to
local_origin
.y (float) β y coordinate relative to
local_origin
.z (float) β z coordinate relative to
local_origin
.
- Returns:
r, theta, and phi coordinates relative to
local_origin
.- Return type:
Tuple[float, float, float]
- static sph_2_car(r, theta, phi)[source]#
Convert spherical to Cartesian coordinates.
- Parameters:
r (float) β radius.
theta (float) β polar angle (rad) downward from x=y=0 line.
phi (float) β azimuthal (rad) angle from y=z=0 line.
- Returns:
x, y, and z coordinates relative to
local_origin
.- Return type:
Tuple[float, float, float]
- static sph_2_car_field(f_r, f_theta, f_phi, theta, phi)[source]#
Convert vector field components in spherical coordinates to cartesian.
- Parameters:
f_r (float) β radial component of the vector field.
f_theta (float) β polar angle component of the vector fielf.
f_phi (float) β azimuthal angle component of the vector field.
theta (float) β polar angle (rad) of location of the vector field.
phi (float) β azimuthal angle (rad) of location of the vector field.
- Returns:
x, y, and z components of the vector field in cartesian coordinates.
- Return type:
Tuple[float, float, float]
- static car_2_sph_field(f_x, f_y, f_z, theta, phi)[source]#
Convert vector field components in cartesian coordinates to spherical.
- Parameters:
f_x (float) β x component of the vector field.
f_y (float) β y component of the vector fielf.
f_z (float) β z component of the vector field.
theta (float) β polar angle (rad) of location of the vector field.
phi (float) β azimuthal angle (rad) of location of the vector field.
- Returns:
radial (s), elevation (theta), and azimuthal (phi) components of the vector field in spherical coordinates.
- Return type:
Tuple[float, float, float]
- static kspace_2_sph(ux, uy, axis)[source]#
Convert normalized k-space coordinates to angles.
- Parameters:
ux (float) β normalized kx coordinate.
uy (float) β normalized ky coordinate.
axis (int) β axis along which the observation plane is oriented.
- Returns:
theta and phi coordinates relative to
local_origin
.- Return type:
Tuple[float, float]
- static load_gds_vertices_gdstk(gds_cell, gds_layer, gds_dtype=None, gds_scale=1.0)[source]#
Load polygon vertices from a
gdstk.Cell
.- Parameters:
gds_cell (gdstk.Cell) β
gdstk.Cell
orgdspy.Cell
containing 2D geometric data.gds_layer (int) β Layer index in the
gds_cell
.gds_dtype (int = None) β Data-type index in the
gds_cell
. IfNone
, imports all data for this layer into the returned list.gds_scale (float = 1.0) β Length scale used in GDS file in units of micrometer. For example, if gds file uses nanometers, set
gds_scale=1e-3
. Must be positive.
- Returns:
List of polygon vertices
- Return type:
List[ArrayFloat2D]
- static load_gds_vertices_gdspy(gds_cell, gds_layer, gds_dtype=None, gds_scale=1.0)[source]#
Load polygon vertices from a
gdspy.Cell
.- Parameters:
gds_cell (gdspy.Cell) β
gdstk.Cell
orgdspy.Cell
containing 2D geometric data.gds_layer (int) β Layer index in the
gds_cell
.gds_dtype (int = None) β Data-type index in the
gds_cell
. IfNone
, imports all data for this layer into the returned list.gds_scale (float = 1.0) β Length scale used in GDS file in units of micrometer. For example, if gds file uses nanometers, set
gds_scale=1e-3
. Must be positive.
- Returns:
List of polygon vertices
- Return type:
List[ArrayFloat2D]
- static from_gds(gds_cell, axis, slab_bounds, gds_layer, gds_dtype=None, gds_scale=1.0, dilation=0.0, sidewall_angle=0, reference_plane='middle')[source]#
Import a
gdstk.Cell
or agdspy.Cell
and extrude it into a GeometryGroup.- Parameters:
gds_cell (Union[gdstk.Cell, gdspy.Cell]) β
gdstk.Cell
orgdspy.Cell
containing 2D geometric data.axis (int) β Integer index defining the extrusion axis: 0 (x), 1 (y), or 2 (z).
slab_bounds (Tuple[float, float]) β Minimal and maximal positions of the extruded slab along
axis
.gds_layer (int) β Layer index in the
gds_cell
.gds_dtype (int = None) β Data-type index in the
gds_cell
. IfNone
, imports all data for this layer into the returned list.gds_scale (float = 1.0) β Length scale used in GDS file in units of micrometer. For example, if gds file uses nanometers, set
gds_scale=1e-3
. Must be positive.dilation (float = 0.0) β Dilation (positive) or erosion (negative) amount to be applied to the original polygons.
sidewall_angle (float = 0) β Angle of the extrusion sidewalls, away from the vertical direction, in radians. Positive (negative) values result in slabs larger (smaller) at the base than at the top.
reference_plane (PlanePosition = "middle") β Reference position of the (dilated/eroded) polygons along the slab axis. One of
"middle"
(polygons correspond to the center of the slab bounds),"bottom"
(minimal slab bound position), or"top"
(maximal slab bound position). This value has no effect ifsidewall_angle == 0
.
- Returns:
Geometries created from the 2D data.
- Return type:
- static from_shapely(shape, axis, slab_bounds, dilation=0.0, sidewall_angle=0, reference_plane='middle')[source]#
Convert a shapely primitive into a geometry instance by extrusion.
- Parameters:
shape (shapely.geometry.base.BaseGeometry) β Shapely primitive to be converted. It must be a linear ring, a polygon or a collection of any of those.
axis (int) β Integer index defining the extrusion axis: 0 (x), 1 (y), or 2 (z).
slab_bounds (Tuple[float, float]) β Minimal and maximal positions of the extruded slab along
axis
.dilation (float) β Dilation of the polygon in the base by shifting each edge along its normal outwards direction by a distance; a negative value corresponds to erosion.
sidewall_angle (float = 0) β Angle of the extrusion sidewalls, away from the vertical direction, in radians. Positive (negative) values result in slabs larger (smaller) at the base than at the top.
reference_plane (PlanePosition = "middle") β Reference position of the (dilated/eroded) polygons along the slab axis. One of
"middle"
(polygons correspond to the center of the slab bounds),"bottom"
(minimal slab bound position), or"top"
(maximal slab bound position). This value has no effect ifsidewall_angle == 0
.
- Returns:
Geometry extruded from the 2D data.
- Return type:
- to_gdstk(x=None, y=None, z=None, gds_layer=0, gds_dtype=0)[source]#
Convert a Geometry objectβs planar slice to a .gds type polygon.
- Parameters:
x (float = None) β Position of plane in x direction, only one of x,y,z can be specified to define plane.
y (float = None) β Position of plane in y direction, only one of x,y,z can be specified to define plane.
z (float = None) β Position of plane in z direction, only one of x,y,z can be specified to define plane.
gds_layer (int = 0) β Layer index to use for the shapes stored in the .gds file.
gds_dtype (int = 0) β Data-type index to use for the shapes stored in the .gds file.
- Returns:
List of gdstk.Polygon.
- Return type:
List
- to_gdspy(x=None, y=None, z=None, gds_layer=0, gds_dtype=0)[source]#
Convert a Geometry objectβs planar slice to a .gds type polygon.
- Parameters:
x (float = None) β Position of plane in x direction, only one of x,y,z can be specified to define plane.
y (float = None) β Position of plane in y direction, only one of x,y,z can be specified to define plane.
z (float = None) β Position of plane in z direction, only one of x,y,z can be specified to define plane.
gds_layer (int = 0) β Layer index to use for the shapes stored in the .gds file.
gds_dtype (int = 0) β Data-type index to use for the shapes stored in the .gds file.
- Returns:
List of gdspy.Polygon and gdspy.PolygonSet.
- Return type:
List
- to_gds(cell, x=None, y=None, z=None, gds_layer=0, gds_dtype=0)[source]#
Append a Geometry objectβs planar slice to a .gds cell.
- Parameters:
cell (
gdstk.Cell
orgdspy.Cell
) β Cell object to which the generated polygons are added.x (float = None) β Position of plane in x direction, only one of x,y,z can be specified to define plane.
y (float = None) β Position of plane in y direction, only one of x,y,z can be specified to define plane.
z (float = None) β Position of plane in z direction, only one of x,y,z can be specified to define plane.
gds_layer (int = 0) β Layer index to use for the shapes stored in the .gds file.
gds_dtype (int = 0) β Data-type index to use for the shapes stored in the .gds file.
- to_gds_file(fname, x=None, y=None, z=None, gds_layer=0, gds_dtype=0, gds_cell_name='MAIN')[source]#
Export a Geometry objectβs planar slice to a .gds file.
- Parameters:
fname (str) β Full path to the .gds file to save the
Geometry
slice to.x (float = None) β Position of plane in x direction, only one of x,y,z can be specified to define plane.
y (float = None) β Position of plane in y direction, only one of x,y,z can be specified to define plane.
z (float = None) β Position of plane in z direction, only one of x,y,z can be specified to define plane.
gds_layer (int = 0) β Layer index to use for the shapes stored in the .gds file.
gds_dtype (int = 0) β Data-type index to use for the shapes stored in the .gds file.
gds_cell_name (str = 'MAIN') β Name of the cell created in the .gds file to store the geometry.
- __hash__()#
Hash method.