Home Forums KLayout Bending Reply To: Bending

#6373
Ronald
Keymaster

Dear Rose,

To make a polygon shape follow an “arbitrary” line would require to transform its polygon from the standard straight coordinate system to one that follows the line. For an arc you can do something like below, where the red shape is the original shape and the blue is wrapped on a circular arc:

from math import sin, cos
import nazca as nd

def create_taper():
    """Create a taper shape as you see fit."""
    dh = 1
    s = 30
    N = 20
    points1 = []
    points2 = []
    for i in range(N + 1):
        scale = -0.5 + i / N
        points1.append((s*scale, dh * (1 - abs(scale))))
        points2.append((-s*scale, -dh *(1 - abs(scale))))
    return points1 + points2                   
    
def bend_polygon(points=None, radius=10):
    """Bend a polygon along a circular arc."""
    pointsout = []
    # Conformal transformation to a circular grid:
    for x, y in points:
        x2 = (radius + y) * sin(x / radius)
        y2 = (radius + y) * cos(x / radius)
        pointsout.append((x2, y2))
    return pointsout
    
with nd.Cell() as C:
    radius = 15
    points = create_taper()
    pointsbend = bend_polygon(points=points, radius=radius)
    nd.Polygon(points=points, layer=1).put(0, radius)
    nd.Polygon(points=pointsbend, layer=2).put(0)

nd.export_png(C)

Ronald