Home › Forums › Nazca › Polygon subtraction function › Reply To: Polygon subtraction function
Hi Kyung Hun Yoon,
Assuming you go the gds format in the end, the polygon should not have crossing lines and should have a “direction” such that if you travel along your polygon, the right hand side of your line always “points” to the area between your rectangle and hexagon. Here some ways to subtract a shape inside another shape:
1. Place the rectangle and hexagon in different mask layers and consider subtraction in a post-processing step on your mask. In KLayout for example you can perform boolean operations fast and efficiently (Edit/Layer/Boolean Operations).
2. Construct your polygon by adding the hexagon points to the rectangle points while taking into account the direction and the closure of the polygons (end-point = start-point), for example:
import nazca as nd
square1 = [(0, -5), (5, 0), (0, 5), (-5, 0), (0, -5)]
square2 = [(-10, -10), (10, -10), (10, 10), (-10, 10), (-10,-10)]
diff = square2 + square1[::-1] # reverse direction of inner shape square1
nd.Polygon(layer=1, points=square1).put()
nd.Polygon(layer=3, points=square2).put()
nd.Polygon(layer=5, points=diff).put(30)
nd.export_gds()
3. Use the pyclipper module in Nazca (nazca.clipper), however, this will not work well for a subtraction of shapes fully inside another shape, because pyclipper is not restricted to gds type of polygon concepts.
Ronald