mirror of
git://projects.qi-hardware.com/cae-tools.git
synced 2025-04-21 12:27:27 +03:00
cameo: adding support for dril/mill substitutions (in progress)
- Makefile (OBJS): added shape.o - README: added section for drill/mill substitutions - lang.l, lang.y: added commands "drill", "empty", "mill", "remainder", and "reset" - lang.y (clear_paths): moved freeing of all paths from "clean" to shared function clear_paths - ops.h, ops.c (try_drill, try_mill): helper functions for "drill" and "mill" commands - shape.h. shape.c (slot, circle): functions to generate toolpaths for basic shapes
This commit is contained in:
83
cameo/shape.c
Normal file
83
cameo/shape.c
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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+x, 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;
|
||||
}
|
||||
Reference in New Issue
Block a user