From 5c9e7d5e5207be46a12601981f8acf0a5c1a7596 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Mon, 1 Nov 2010 16:42:32 -0300 Subject: [PATCH] Corrected math for offsets to work also for angles different from 90 degrees. - cameo/path.c (offset_point): calculation assumed the normals were linearly independent. Replaced it with corrected version. --- cameo/path.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/cameo/path.c b/cameo/path.c index 88f4289..65d5294 100644 --- a/cameo/path.c +++ b/cameo/path.c @@ -104,6 +104,7 @@ static struct point *offset_point(const struct point *a, const struct point *b, double ax, ay, bx, by; double aa, bb; double nx, ny; + double angle, f; struct point *p; ax = b->x-a->x; @@ -113,6 +114,7 @@ static struct point *offset_point(const struct point *a, const struct point *b, aa = hypot(ax, ay); bb = hypot(bx, by); + if (left) { nx = -(ay/aa+by/bb); ny = ax/aa+bx/bb; @@ -121,8 +123,15 @@ static struct point *offset_point(const struct point *a, const struct point *b, ny = -(ax/aa+bx/bb); } - nx *= off; - ny *= off; + /* angle between AB and BC */ + angle = acos(-(ax*bx+ay*by)/aa/bb); + + /* multiplier for combination of normal vectors */ + f = off/sin(angle/2); + f /= hypot(nx, ny); + + nx *= f; + ny *= f; p = alloc_type(struct point); p->x = b->x+nx;