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;