From 32f36ccbc46ec2d5c7fb5a349c8eaa1616dd5a35 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Wed, 8 Dec 2010 05:52:58 -0300 Subject: [PATCH] drl2gp.c: added milling of slots (more to come) --- drl2gp/drl2gp.c | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/drl2gp/drl2gp.c b/drl2gp/drl2gp.c index fdc3813..99eedaa 100644 --- a/drl2gp/drl2gp.c +++ b/drl2gp/drl2gp.c @@ -137,9 +137,51 @@ static void header(void) } +static double arc2angle(double arc, double r) +{ + return acos(1-arc*arc/(r*r)/2); +} + + +static void half_circle(double cx, double cy, double rx, double ry, double s) +{ + double m[4]; + double x = rx, y = ry, tmp; + double a; + + m[0] = cos(s); + m[1] = -sin(s); + m[2] = -m[1]; + m[3] = m[0]; + + for (a = 0; a < M_PI; a += s) { + printf("%f %f %f\n", cx+x, cy+y, -depth); + tmp = x*m[0]+y*m[1]; + y = x*m[2]+y*m[3]; + x = tmp; + } + printf("%f %f %f\n", cx-rx, cy-ry, -depth); +} + + static void slot(double xa, double ya, double xb, double yb, double d) { + double dx = xb-xa; + double dy = yb-ya; + double cr = d/2; + double tr = d0/2; + double s = arc2angle(MAX_STEP, cr); + double nx, ny; + double f; + assert(mill); + f = (cr-tr)/hypot(dx, dy); + nx = -dy*f; + ny = dx*f; + + half_circle(xa, ya, nx, ny, s); + half_circle(xb, yb, -nx, -ny, s); + printf("%f %f %f\n\n", xa+nx, ya+ny, -depth); } @@ -147,7 +189,7 @@ static void circle(double cx, double cy, double d) { double cr = d/2; double tr = d0/2; - double s = acos(1-MAX_STEP*MAX_STEP/(cr*cr)/2); + double s = arc2angle(MAX_STEP, cr); double a; assert(mill);