mirror of
git://projects.qi-hardware.com/cae-tools.git
synced 2024-12-23 09:17:42 +02:00
7a64e425da
- README: changed the term "drill/mill substitution" to "drill/mill conversion" - README: described the drill/mill conversion commands - lang.y: "drill" and "mill" worked on the wrong (empty) list - ops.c (half_circle): fixed transcription error
84 lines
1.6 KiB
C
84 lines
1.6 KiB
C
/*
|
|
* shape.c - Toolpaths for basic shapes
|
|
*
|
|
* Written 2010 by Werner Almesberger
|
|
* Copyright 2010 Werner Almesberger
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*/
|
|
|
|
|
|
#include <math.h>
|
|
|
|
#include "path.h"
|
|
#include "shape.h"
|
|
|
|
|
|
static struct path *path;
|
|
|
|
|
|
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 z,
|
|
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) {
|
|
path_add(path, cx+x, cy+y, z);
|
|
tmp = x*m[0]+y*m[1];
|
|
y = x*m[2]+y*m[3];
|
|
x = tmp;
|
|
}
|
|
path_add(path, cx-rx, cy-ry, z);
|
|
}
|
|
|
|
|
|
struct path *slot(double xa, double ya, double xb, double yb, double z,
|
|
double sr, double tr, double step)
|
|
{
|
|
double dx = xb-xa;
|
|
double dy = yb-ya;
|
|
double s = arc2angle(step, sr);
|
|
double nx, ny;
|
|
double f;
|
|
|
|
f = (sr-tr)/hypot(dx, dy);
|
|
nx = -dy*f;
|
|
ny = dx*f;
|
|
|
|
path = path_new(tr);
|
|
half_circle(xa, ya, nx, ny, z, s);
|
|
half_circle(xb, yb, -nx, -ny, z, s);
|
|
path_add(path, xa+nx, ya+ny, z);
|
|
return path;
|
|
}
|
|
|
|
|
|
struct path *circle(double cx, double cy, double cz, double cr, double tr,
|
|
double step)
|
|
{
|
|
double s = arc2angle(step, cr);
|
|
double a;
|
|
|
|
path = path_new(tr);
|
|
for (a = 0; a < 2*M_PI; a += s)
|
|
path_add(path, cx+(cr-tr)*cos(a), cy+(cr-tr)*sin(a), cz);
|
|
path_add(path, cx+(cr-tr), cy, cz);
|
|
return path;
|
|
}
|