mirror of
git://projects.qi-hardware.com/cae-tools.git
synced 2025-01-03 20:10:15 +02:00
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.
This commit is contained in:
parent
54d8549fa2
commit
5c9e7d5e52
13
cameo/path.c
13
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;
|
||||
|
Loading…
Reference in New Issue
Block a user