Index: Makefile =================================================================== --- Makefile (nonexistent) +++ Makefile (revision 37159) @@ -0,0 +1,10 @@ +CFLAGS = -Wall -g +LDFLAGS = -lm + + +main: main.o sbiarc.o + +main.o: main.c sbiarc.h + +sbiarc.o: sbiarc.c sbiarc.h + Index: main.c =================================================================== --- main.c (nonexistent) +++ main.c (revision 37159) @@ -0,0 +1,12 @@ +#include "sbiarc.h" + +int main() +{ + sba_t s; + s.cx[0] = 10; s.cy[0] = 1; s.r[0] = 5; + s.cx[1] = 40; s.cy[1] = 5; s.r[1] = 9; + s.style = SBA_STRAIGHT; + + sba_update(&s); + +} Index: sbiarc.c =================================================================== --- sbiarc.c (nonexistent) +++ sbiarc.c (revision 37159) @@ -0,0 +1,35 @@ +#include "sbiarc.h" + +int sba_update(sba_t *s) +{ + sba_calc_t vx, vy, vlen; /* vector between centers */ + sba_calc_t vipx, vipy, vipl; /* inflection point on v */ + sba_calc_t ipx, ipy, ipr; /* "inflection" point on the curve, where r is halfway between r[0] and r[1] */ + + vx = s->cx[1] - s->cx[0]; vy = s->cy[1] - s->cy[0]; + if ((vx == 0) && (vy == 0)) { +#warning TODO: single arc + abort(); + } + vlen = sqrt(vx*vx + vy*vy); + vx /= vlen; vy /= vlen; + + vipl = s->r[0] / (s->r[0] + s->r[1]); + vipx = s->cx[0] + vx * vipl; vipy = s->cy[0] + vy * vipl; + + ipr = (s->r[0] + s->r[1])/2; + + if (s->style == SBA_STRAIGHT) { + ipx = vipx + -vy * ipr; ipy = vipy + vx * ipr; + } + else { + ipx = vipx; ipy = vipy; + } + + s->ipa[0] = atan2(ipy - s->cy[0], ipx - s->cx[0]); + s->ipa[1] = atan2(ipy - s->cy[1], ipx - s->cx[1]); + + return 0; +} + + Index: sbiarc.h =================================================================== --- sbiarc.h (nonexistent) +++ sbiarc.h (revision 37159) @@ -0,0 +1,23 @@ +typedef double sba_coord_t; +typedef double sba_calc_t; +typedef double sba_angle_t; + +typedef enum sba_style_e { + SBA_INFLEX, + SBA_STRAIGHT, + SBA_SINGLE, /* single arc: same center point and radius */ +} sba_style_t; + +typedef struct { + + /* public/configuration */ + sba_coord_t cx[2], cy[2], r[2]; /* center point and radius for two arcs */ + sba_angle_t start, delta; /* endpoint's angle is start+delta but delta's sign matters */ + sba_style_t style; + + /* private/cache */ + sba_angle_t ipa[2]; /* inflexion point angle from c[0] and c[1] */ +} sba_t; + + +int sba_update(sba_t *s);