generate inset polygon and mounting holes

This commit is contained in:
Trammell Hudson 2015-02-15 16:17:08 -05:00
parent b5210c4d65
commit f2031577f0

110
corners.c
View File

@ -20,8 +20,11 @@ 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 = 6; const double thickness = 3;
const double offset = 8; const double inset_dist = 2;
const double hole_dist = 4;
const double hole_rad = 3.0/2;
const double hole_height = 40;
// for each vertex, find the coplanar triangles // for each vertex, find the coplanar triangles
// \todo: do coplanar bits // \todo: do coplanar bits
@ -36,7 +39,7 @@ main(void)
"translate([%f,%f,%f])\n" "translate([%f,%f,%f])\n"
"//render() difference()\n" "//render() difference()\n"
"{\n" "{\n"
"sphere(r=20);\n", "sphere(r=15);\n",
i, origin.p[0], origin.p[1], origin.p[2]); i, origin.p[0], origin.p[1], origin.p[2]);
int * const face_used = calloc(sizeof(*face_used), stl->num_face); int * const face_used = calloc(sizeof(*face_used), stl->num_face);
@ -63,19 +66,10 @@ main(void)
f->vertex[(start_vertex+2) % 3]->p f->vertex[(start_vertex+2) % 3]->p
); );
const stl_vertex_t * const v1 = vertex_list[0];
const stl_vertex_t * const v2 = vertex_list[1];
const v3_t d = v3_sub(v2->p, v1->p);
const float len = v3_len(&v2->p, &v1->p);
//const float b = acos(d.p[2] / len) * 180/M_PI;
//const float c = d.p[0] == 0 ? sign(d.p[1]) * 90 : atan2(d.p[1], d.p[0]) * 180/M_PI;
//
// use the transpose of the rotation matrix, // use the transpose of the rotation matrix,
// which will rotate from (x,y) to the correct // which will rotate from (x,y) to the correct
// orientation relative to this connector node. // orientation relative to this connector node.
printf("multmatrix(m=[[%f,%f,%f,0],[%f,%f,%f,0],[%f,%f,%f,0],[0,0,0,1]]) {\n",
printf("multmatrix(m=[[%f,%f,%f,0],[%f,%f,%f,0],[%f,%f,%f,0],[0,0,0,1]]) translate([0,0,%f]) linear_extrude(height=%f) polygon(points=[\n",
ref.x.p[0], ref.x.p[0],
ref.y.p[0], ref.y.p[0],
ref.z.p[0], ref.z.p[0],
@ -84,8 +78,11 @@ main(void)
ref.z.p[1], ref.z.p[1],
ref.x.p[2], ref.x.p[2],
ref.y.p[2], ref.y.p[2],
ref.z.p[2], ref.z.p[2]
//a, b, c, );
// generate the polygon plane
printf("translate([0,0,%f]) linear_extrude(height=%f) polygon(points=[\n",
-thickness/2, -thickness/2,
thickness thickness
); );
@ -93,73 +90,32 @@ main(void)
for(int k=0 ; k < vertex_count ; k++) for(int k=0 ; k < vertex_count ; k++)
{ {
double x, y; double x, y;
v3_project(&ref, vertex_list[k]->p, &x, &y); refframe_inset(&ref, inset_dist, &x, &y,
vertex_list[(k+0) % vertex_count]->p,
vertex_list[(k+1) % vertex_count]->p,
vertex_list[(k+2) % vertex_count]->p
);
printf("[%f,%f],", x, y); printf("[%f,%f],", x, y);
} }
printf("\n]);\n"); printf("\n]);\n");
// generate a polyhedron that spans // generate the mounting holes
// the width of this coplanar thingy for(int k=0 ; k < vertex_count ; k++)
#if 0 {
v3_t v0 = v3_sub(f->vertex[0]->p, origin); double x, y;
v3_t v1 = v3_sub(f->vertex[1]->p, origin); refframe_inset(&ref, inset_dist+hole_dist, &x, &y,
v3_t v2 = v3_sub(f->vertex[2]->p, origin); vertex_list[(k+0) % vertex_count]->p,
v3_t n; vertex_list[(k+1) % vertex_count]->p,
vertex_list[(k+2) % vertex_count]->p
);
printf("translate([%f,%f,0]) cylinder(r=%f,h=%f, center=true);\n",
x, y,
hole_rad,
hole_height
);
}
// compute normal of the face printf("}\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+1)/v3_mag(n)/2);
// slide the vectors towards the center
v3_t v0mid = v3_scale(v3_mid(v0, v1, v2), offset);
v3_t v1mid = v3_scale(v3_mid(v1, v0, v2), offset);
v3_t v2mid = v3_scale(v3_mid(v2, v0, v1), offset);
v0 = v3_add(v0, v0mid);
v1 = v3_add(v1, v1mid);
v2 = v3_add(v2, v2mid);
// compute the
v3_t v3 = v3_add(v0, n);
v3_t v4 = v3_add(v1, n);
v3_t v5 = v3_add(v2, n);
v0 = v3_sub(v0, n);
v1 = v3_sub(v1, n);
v2 = v3_sub(v2, n);
printf("polyhedron(\n"
"points=[\n"
"[%f,%f,%f],[%f,%f,%f],[%f,%f,%f],\n"
"[%f,%f,%f],[%f,%f,%f],[%f,%f,%f],\n"
"], %s = ["
" [0,1,2], [3,5,4],"
" [0,2,3], [2,5,3],"
" [0,3,4], [0,4,1],"
" [1,4,5], [1,5,2],"
"]);\n",
v0.p[0], v0.p[1], v0.p[2],
v1.p[0], v1.p[1], v1.p[2],
v2.p[0], v2.p[1], v2.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],
#ifdef __linux__
"triangles"
#else
"faces"
#endif
);
#endif
//break; // only do one right now
} }
free(face_used); free(face_used);