Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Absolute Coordinates of Reference #236

Open
Rishabhgoyal07 opened this issue Feb 12, 2024 · 1 comment
Open

Absolute Coordinates of Reference #236

Rishabhgoyal07 opened this issue Feb 12, 2024 · 1 comment

Comments

@Rishabhgoyal07
Copy link

Hello @heitzmann, I want to ask that, how can I get the absolute coordinates of a reference according to its placement in a defined layout. Can we directly access a reference down the hierarchy?

@nmz787-intel
Copy link

nmz787-intel commented Mar 7, 2024

I think you have a few options:

I think for the latter two cases, you want to operate on a cell's .references, not on a Reference object that you just created.:

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)
    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)


# now check references
ref_ids1 = set(triangle_array_8_over_360_deg.references)
ref_ids2 = set(triangle_array_4_over_90_deg.references)
print(ref_ids1)
print(ref_ids2)
common_refs = ref_ids1.intersection(ref_ids2)
print(f'common references: {common_refs}')
assert not common_refs

for ref in triangle_array_4_over_90_deg.references:
    print(f'reference BB: {ref.bounding_box()}')
    for i, p in enumerate(ref.get_polygons()):
        print(f'\t polygon #{i} points: {",".join([str(pts) for pts in p.points])}')
lib.write_gds("testissue.gds")

for me the output is:

{<gdstk.Reference object at 0x2aaae13d5c10>, <gdstk.Reference object at 0x2aaae13d5b30>, <gdstk.Reference object at 0x2aaae13d5b50>, <gdstk.Reference object at 0x2aaae13d5b70>, <gdstk.Reference object at 0x2aaae13d5b90>, <gdstk.Reference object at 0x2aaae13d5bb0>, <gdstk.Reference object at 0x2aaae13d5bd0>, <gdstk.Reference object at 0x2aaae13d5bf0>}
{<gdstk.Reference object at 0x2aaae13d5a70>, <gdstk.Reference object at 0x2aaae13d5a30>, <gdstk.Reference object at 0x2aaae13d5a50>, <gdstk.Reference object at 0x2aaae13d59f0>}
common references: set()
reference BB: ((-1.0, 4.8452994616207485), (1.0000000000000007, 6.577350269189626))
	 polygon #0 points: [-1.          6.57735027],[-2.12115048e-16  4.84529946e+00],[1.         6.57735027]
reference BB: ((2.422649730810374, 4.196152422706632), (4.1547005383792515, 6.196152422706633))
	 polygon #0 points: [2.42264973 6.19615242],[2.42264973 4.19615242],[4.15470054 5.19615242]
reference BB: ((4.196152422706632, 2.4226497308103743), (6.196152422706632, 4.154700538379252))
	 polygon #0 points: [5.19615242 4.15470054],[4.19615242 2.42264973],[6.19615242 2.42264973]
reference BB: ((4.8452994616207485, -1.0000000000000004), (6.577350269189626, 1.0000000000000004))
	 polygon #0 points: [6.57735027 1.        ],[4.84529946e+00 5.08804072e-16],[ 6.57735027 -1.        ]

dtzikas pushed a commit to dtzikas/gdstk that referenced this issue Apr 18, 2024
Signed-off-by: Lucas Heitzmann Gabrielli <heitzmann@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants