1
0
mirror of git://projects.qi-hardware.com/cae-tools.git synced 2024-12-22 18:21:08 +02:00

ptrude/: cleanup and addition of comments (WIP)

- arc.fig: corrected formula for 2t
- path.c (corner): cleanup and added comments
This commit is contained in:
Werner Almesberger 2011-07-28 22:52:42 -03:00
parent d4c96f129d
commit dcb1c7856a
2 changed files with 30 additions and 18 deletions

View File

@ -60,7 +60,7 @@ Single
4 1 0 50 -1 18 18 0.0000 4 195 240 8505 7380 2t\001
4 0 0 50 -1 18 18 0.0000 4 270 2085 9405 7200 (r-d)^2+u^2=r^2\001
4 0 0 50 -1 18 18 0.0000 4 270 2610 9405 7650 (r-d)^2+v^2=(r+d)^2\001
4 0 0 50 -1 18 18 0.0000 4 270 1530 9405 8100 2t = 2p+n*q\001
4 0 0 50 -1 18 18 0.0000 4 270 2400 9405 8100 2t = 2*(p+(n+1)*q)\001
4 0 0 50 -1 18 18 0.0000 4 210 915 4410 3105 ...+q+p\001
4 1 0 50 -1 18 18 0.0000 4 210 180 4950 3555 q\001
4 1 0 50 -1 18 18 0.0000 4 210 180 4635 3870 q\001

View File

@ -95,20 +95,38 @@ static const struct vertex *add_vertex(struct path *path, double x, double y,
static const struct vertex *corner(struct path *path, const struct vertex *a,
const struct vertex *b, const struct vertex *c, double r, double d)
{
/* points to vectors */
double ax = b->x-a->x;
double ay = b->y-a->y;
double bx = c->x-b->x;
double by = c->y-b->y;
/* vector length */
double aa = hypot(ax, ay);
double bb = hypot(bx, by);
/* dot and cross product */
double dp = ax*bx+ay*by; /* a * b = a*b*cos 2t */
double cp = ax*by-ay*bx; /* |a x b| = a*b*sin 2t */
double dd; /* "d" of the given vectors */
double tt, s;
double t2, p, q, ang;
double u, v;
double f, x, y;
int n, i;
double dir = copysign(1, cp);
/* see corner.fig */
double dd; /* "d" of the given vectors */
double tt; /* tan t */
double s; /* distance between start of arc and corner */
double t2; /* angle, t*2 */
/* see arc.fig */
double p; /* half-angle of border side of border segment */
double q; /* half-angle of connecting segment */
double u; /* length of border side of border segment */
double v; /* half-length of connecting segment */
int n; /* number of connecting segments (0 if none) */
double f; /* scale factor; various uses */
double ang; /* current angle, for iteration */
double x, y; /* current position; for iteration */
int i; /* segment; for iteration */
/*
* http://en.wikipedia.org/wiki/Dot_product
@ -212,24 +230,18 @@ static const struct vertex *corner(struct path *path, const struct vertex *a,
n = (int) ceil((t2-2*(p+q))/(2*q));
/*
* @@@ We should evenly distribute the slack, but that seems
* difficult. For now, we just center the polygon.
* @@@ We should evenly distribute the slack and try to pick a
* smaller value for d, but that seems difficult.
*
* For now, we just center the polygon.
*/
q = (t2/2-p)/(n+1);
double dir = copysign(1, cp);
#if 0
if (cp < 0) {
// t2 = -t2;
q = -q;
p = -p;
}
#endif
if (n)
ang = p+q;
else
ang = t2/2;
u = tan(p)*(r-d);
v = tan(q)*(r-d);
f = (u+v)/aa;