generate two planes, separated by thickness

This commit is contained in:
Trammell Hudson 2015-02-14 20:03:39 -05:00
parent 5cda4d37b8
commit c2293062f3

View File

@ -20,6 +20,7 @@ main(void)
stl_3d_t * const stl = stl_3d_parse(STDIN_FILENO); stl_3d_t * const stl = stl_3d_parse(STDIN_FILENO);
if (!stl) if (!stl)
return EXIT_FAILURE; return EXIT_FAILURE;
const double thickness = 3;
// for each vertex, find the coplanar triangles // for each vertex, find the coplanar triangles
// \todo: do coplanar bits // \todo: do coplanar bits
@ -37,17 +38,40 @@ main(void)
for (int j = 0 ; j < v->num_face; j++) for (int j = 0 ; j < v->num_face; j++)
{ {
const stl_face_t * const f = v->face[j]; const stl_face_t * const f = v->face[j];
v3_t v1 = v3_sub(f->vertex[0]->p, origin); v3_t v0 = v3_sub(f->vertex[0]->p, origin);
v3_t v2 = v3_sub(f->vertex[1]->p, origin); v3_t v1 = v3_sub(f->vertex[1]->p, origin);
v3_t v3 = v3_sub(f->vertex[2]->p, origin); v3_t v2 = v3_sub(f->vertex[2]->p, origin);
v3_t n;
if (v->face_num[j] == 0)
n = v3_cross(v1, v2);
else
if (v->face_num[j] == 1)
n = v3_cross(v2, v0);
else
if (v->face_num[j] == 2)
n = v3_cross(v0, v1);
n = v3_scale(n, thickness/v3_mag(n)/2);
v0 = v3_add(v0, n);
v1 = v3_add(v1, n);
v2 = v3_add(v2, n);
v3_t v3 = v3_sub(v0, n);
v3_t v4 = v3_sub(v1, n);
v3_t v5 = v3_sub(v2, n);
printf("%%polyhedron(\n" printf("%%polyhedron(\n"
"points=[\n" "points=[\n"
"[%f,%f,%f],[%f,%f,%f],[%f,%f,%f],\n" "[%f,%f,%f],[%f,%f,%f],[%f,%f,%f],\n"
"], faces = [[0,1,2]]);\n", "[%f,%f,%f],[%f,%f,%f],[%f,%f,%f],\n"
"], faces = [[0,1,2], [3,4,5]]);\n",
v0.p[0], v0.p[1], v0.p[2],
v1.p[0], v1.p[1], v1.p[2], v1.p[0], v1.p[1], v1.p[2],
v2.p[0], v2.p[1], v2.p[2], v2.p[0], v2.p[1], v2.p[2],
v3.p[0], v3.p[1], v3.p[2] v3.p[0], v3.p[1], v3.p[2],
v4.p[0], v4.p[1], v4.p[2],
v5.p[0], v5.p[1], v5.p[2]
); );
/* /*
@ -58,10 +82,11 @@ main(void)
f->face[2] ? f->face[2] - stl->face : -1, f->angle[2] f->face[2] ? f->face[2] - stl->face : -1, f->angle[2]
); );
*/ */
break; // only do one right now
} }
printf("}\n"); printf("}\n");
break; break; // only do one right now
} }
return 0; return 0;