Пример #1
0
def getParallelPath(L, d):
    """
    Dato il Path `L` torna il Path `parallelo` ad L a distanza `d`.
    Costruisce la parallela proiettando i punti della spezzata L a distanza d
    (corretta per l'angolo tra i segmenti) in direzione normale a L.
    """
    EPS = 1E-3
    pts = []
    for i, p in enumerate(L):
        s = L.len(i)
        try:
            t1 = geo2d.dir(L(s) - L(s - EPS))
        except ZeroDivisionError:
            t1 = geo2d.P(1, 0)
        try:
            t2 = geo2d.dir(L(s + EPS) - L(s))
        except ZeroDivisionError:
            t2 = geo2d.P(1, 0)
        n1 = geo2d.ortho(t1)
        n2 = geo2d.ortho(t2)
        n = geo2d.dir(n1 + n2) * d * math.sqrt(2.0 / (1.0 + n1 * n2 * 0.999))
        pts.append(p + n)

    return geo2d.Path(pts)