1
0
mirror of git://projects.qi-hardware.com/cae-tools.git synced 2025-04-21 12:27:27 +03:00

ptrude/: many major math fixes, especially in stretch_path

This commit is contained in:
Werner Almesberger
2011-07-31 19:17:05 -03:00
parent ee634458dc
commit 26a0f4cf2b
6 changed files with 161 additions and 25 deletions

View File

@@ -14,14 +14,14 @@
* Known bugs:
*
* - negative x coordinates in shape produce overlapping faces
* - the rounding is only accurate for x = 0. For x > 0, we need to add
* more points. Tricky.
*/
#include <stdlib.h>
#include <math.h>
#include <assert.h>
#include "ptrude.h"
#include "path.h"
#include "extrude.h"
@@ -34,6 +34,26 @@ static void cvt_3d(struct point *p, const struct vertex *v, double z)
}
static void size(const struct path *p)
{
const struct vertex *v, *next;
double s = 0, sl = 0;
int n = 0;
if (!debug)
return;
for (v = p->vertices; v; v = next) {
next = v->next;
if (next)
s += hypot(v->x-next->x, v->y-next->y);
sl += v->len;
n++;
}
fprintf(stderr, "%d virt %g real %g\n", n, sl, s);
}
static void mesh(const struct path *pa, double za,
const struct path *pb, double zb,
void (*face)(void *data, struct point a, struct point b, struct point c),
@@ -47,6 +67,7 @@ static void mesh(const struct path *pa, double za,
cvt_3d(&a3, a, za);
cvt_3d(&b3, b, zb);
while (a->next || b->next) {
da = fabs(sa+a->len-sb);
db = fabs(sb+b->len-sa);
@@ -83,14 +104,18 @@ void extrude(const struct path *path, const struct path *shape,
if (!v || !v->next)
return;
tmp = stretch_path(path, v->x);
tmp = stretch_path(path, v->x, r);
size(tmp);
prev = round_path(tmp, r, d);
free_path(tmp);
size(prev);
while (v->next) {
next = v->next;
tmp = stretch_path(path, next->x);
tmp = stretch_path(path, next->x, r);
size(tmp);
curr = round_path(tmp, r, d);
size(curr);
free_path(tmp);
mesh(prev, v->y, curr, next->y, face, data);