It looks like you're new here. If you want to get involved, click one of these buttons!
This is the code which shows three hexagon with the same center but different size. I want to subtract layer 1 from layer two. so that its look like u have hollow hexagon, that have the smaller hexagon in it. can anyone help me with this. thank you
import pya
import math
layout = pya.Layout()
top_cell = layout.create_cell("TOP")
l1 = layout.layer(1, 0)
l2 = layout.layer(2, 0)
l3 = layout.layer(3, 0)
hex_size = 1000 # microns sides of the hexagon
hollow_size = 500 #
cts_size=250
x0=0
y0=0
def create_hexagon(center, size):
angle_deg = 60
angle_rad = angle_deg * math.pi / 180
points = []
for i in range(6):
x = center.x + size * math.cos(i * angle_rad)
y = center.y + size * math.sin(i * angle_rad)
points.append(pya.Point(x, y))
return pya.Polygon(points)
for i in range(1):
x=0
y=0
center = pya.Point(x, y)
hexagon1 = create_hexagon(center, hex_size)
top_cell.shapes(l1).insert(hexagon1)
hexagon2 = create_hexagon(center, hollow_size)
top_cell.shapes(l2).insert(hexagon2)
hexagon3 = create_hexagon(center,cts_size)
top_cell.shapes(l3).insert(hexagon3)
layout.write("hexagons_7.gds")
Comments
@nairica Python is very hard to read when not formatted as code. Please use three backticks in one line before and after the code like described here: https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks
To perform boolean operations, use the
Region
class. A region is a collection of polygons (what you call a layer) and supports boolean operations. You can compute the desired result in a region and write it into the cell like single polygons. More information here: https://www.klayout.de/doc-qt5/programming/geometry_api.html#k_22Matthias