diff options
author | Roozbeh Pournader <roozbeh@google.com> | 2014-07-26 11:20:29 -0700 |
---|---|---|
committer | Roozbeh Pournader <roozbeh@google.com> | 2014-07-26 11:20:29 -0700 |
commit | 0f1bd27678fb542f8601bbaf493baa1c22732fe2 (patch) | |
tree | 78ecb8f8082fb1b3ae24720549578b9272f36f0c /third_party/spiro/curves/offset.py | |
parent | 5a480b939b43dec473550292501a88518fe1208c (diff) |
Add Spiro version 0.01.
Diffstat (limited to 'third_party/spiro/curves/offset.py')
-rw-r--r-- | third_party/spiro/curves/offset.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/third_party/spiro/curves/offset.py b/third_party/spiro/curves/offset.py new file mode 100644 index 0000000..c528aec --- /dev/null +++ b/third_party/spiro/curves/offset.py @@ -0,0 +1,21 @@ +# offset curve of piecewise cornu curves + +from math import * + +import pcorn +from clothoid import mod_2pi + +def seg_offset(seg, d): + th0 = seg.th(0) + th1 = seg.th(seg.arclen) + z0 = [seg.z0[0] + d * sin(th0), seg.z0[1] - d * cos(th0)] + z1 = [seg.z1[0] + d * sin(th1), seg.z1[1] - d * cos(th1)] + chth = atan2(z1[1] - z0[1], z1[0] - z0[0]) + return [pcorn.Segment(z0, z1, mod_2pi(chth - th0), mod_2pi(th1 - chth))] + + +def offset(curve, d): + segs = [] + for seg in curve.segs: + segs.extend(seg_offset(seg, d)) + return pcorn.Curve(segs) |