| 1 |
|
| 2 |
|
| 3 |
from math import * |
| 4 |
|
| 5 |
import pcorn |
| 6 |
from clothoid import mod_2pi |
| 7 |
|
| 8 |
def seg_offset(seg, d): |
| 9 |
th0 = seg.th(0) |
| 10 |
th1 = seg.th(seg.arclen) |
| 11 |
z0 = [seg.z0[0] + d * sin(th0), seg.z0[1] - d * cos(th0)] |
| 12 |
z1 = [seg.z1[0] + d * sin(th1), seg.z1[1] - d * cos(th1)] |
| 13 |
chth = atan2(z1[1] - z0[1], z1[0] - z0[0]) |
| 14 |
return [pcorn.Segment(z0, z1, mod_2pi(chth - th0), mod_2pi(th1 - chth))] |
| 15 |
|
| 16 |
|
| 17 |
def offset(curve, d): |
| 18 |
segs = [] |
| 19 |
for seg in curve.segs: |
| 20 |
segs.extend(seg_offset(seg, d)) |
| 21 |
return pcorn.Curve(segs) |