heitzmann / gdstk

Gdstk (GDSII Tool Kit) is a C++/Python library for creation and manipulation of GDSII and OASIS files.
https://heitzmann.github.io/gdstk/
Boost Software License 1.0
337 stars 84 forks source link

Add radial arrays to documentation? #232

Open andrgeri opened 8 months ago

andrgeri commented 8 months ago

I don't know if this may be useful, but I was wondering if there is an easy way to realize a radial array. For instance, given the number of copies $N$ and the rotation angle $\theta$, obtain something like the following:

radial_array

While it can be done using a repetition, it isn't exactly straightforward (at least to me). Would it be possible to provide an example in the documentation?

nmz787-intel commented 7 months ago

I think this accomplishes what you want?

import math
import gdstk

lib = gdstk.Library()

# Create a cell with collection of shapes that is used repeatedly
triangle = gdstk.regular_polygon((0, 6), 2, 3, rotation=math.pi)
single_triangle_cell = lib.new_cell("TRIANGLE_SINGLE")
single_triangle_cell.add(triangle)

def add_array(input_cell, output_cell, degrees_sweep, total_triangles):
    number_repetitions = total_triangles
    num_extra_triangles_from_full_rotation_sweep = degrees_sweep//360
    degrees_separation = degrees_sweep/(number_repetitions-1+num_extra_triangles_from_full_rotation_sweep)
    print(num_extra_triangles_from_full_rotation_sweep)
    assert number_repetitions>0
    for i in range(number_repetitions):
        rotated_ref = gdstk.Reference(input_cell, (0, 0), rotation=-math.radians(degrees_separation*i))
        output_cell.add(rotated_ref)
    return output_cell

triangle_array_4_over_90_deg = add_array(single_triangle_cell, lib.new_cell("4_TRIANGLE_ARRAY"), 90, 4)
triangle_array_3_over_90_deg = add_array(single_triangle_cell, lib.new_cell("3_TRIANGLE_ARRAY"), 90, 3)
triangle_array_8_over_360_deg = add_array(single_triangle_cell, lib.new_cell("8_TRIANGLE_ARRAY"), 360, 8)

lib.write_gds("testissue.gds")