move corners to inside of the face, rather than end-caps.

This commit is contained in:
Trammell Hudson 2015-02-22 17:32:06 -05:00
parent 0c3a89ff0f
commit a8383cced0
2 changed files with 75 additions and 32 deletions

105
corners.c
View File

@ -1,6 +1,8 @@
/** \file /** \file
* Generate an OpenSCAD with connectors for each face. * Generate an OpenSCAD with connectors for each face.
* *
* Options are inside only (with face flush on outside)
* or with a slot for the face (like a corner cap)
*/ */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -14,18 +16,44 @@
#include "stl_3d.h" #include "stl_3d.h"
static v3_t avg_x, avg_y, avg_z;
static void
print_multmatrix(
const refframe_t * const ref,
const int transpose
)
{
printf("multmatrix(m=["
"[%f,%f,%f,0],"
"[%f,%f,%f,0],"
"[%f,%f,%f,0],"
"[ 0, 0, 0,1]])\n",
transpose ? ref->x.p[0] : ref->x.p[0],
transpose ? ref->x.p[1] : ref->y.p[0],
transpose ? ref->x.p[2] : ref->z.p[0],
transpose ? ref->y.p[0] : ref->x.p[1],
transpose ? ref->y.p[1] : ref->y.p[1],
transpose ? ref->y.p[2] : ref->z.p[1],
transpose ? ref->z.p[0] : ref->x.p[2],
transpose ? ref->z.p[1] : ref->y.p[2],
transpose ? ref->z.p[2] : ref->z.p[2]
);
}
static void static void
make_faces( make_faces(
const stl_3d_t * const stl, const stl_3d_t * const stl,
const stl_vertex_t * const v, const stl_vertex_t * const v,
const double thickness, const double thickness,
const double translate,
const double inset_dist, const double inset_dist,
const double hole_dist, const double hole_dist,
const double hole_rad const double hole_rad,
const double hole_height
) )
{ {
int * const face_used = calloc(sizeof(*face_used), stl->num_face); int * const face_used = calloc(sizeof(*face_used), stl->num_face);
const double hole_height = 40;
// generate all of the coplanar polygons at this vertex // generate all of the coplanar polygons at this vertex
const stl_vertex_t ** const vertex_list = calloc(sizeof(**vertex_list), stl->num_vertex); const stl_vertex_t ** const vertex_list = calloc(sizeof(**vertex_list), stl->num_vertex);
@ -53,24 +81,21 @@ make_faces(
f->vertex[(start_vertex+2) % 3]->p f->vertex[(start_vertex+2) % 3]->p
); );
avg_x = v3_add(avg_x, ref.x);
avg_y = v3_add(avg_y, ref.y);
avg_z = v3_add(avg_z, ref.z);
// 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", print_multmatrix(&ref, 0);
ref.x.p[0], printf("{\n");
ref.y.p[0],
ref.z.p[0],
ref.x.p[1],
ref.y.p[1],
ref.z.p[1],
ref.x.p[2],
ref.y.p[2],
ref.z.p[2]
);
// generate the polygon plane // generate the polygon plane
if (thickness != 0)
{
printf("translate([0,0,%f]) linear_extrude(height=%f) polygon(points=[\n", printf("translate([0,0,%f]) linear_extrude(height=%f) polygon(points=[\n",
-thickness/2, translate,
thickness thickness
); );
@ -85,9 +110,10 @@ make_faces(
printf("[%f,%f],", x, y); printf("[%f,%f],", x, y);
} }
printf("\n]);\n"); printf("\n]);\n");
}
// generate the mounting holes // generate the mounting holes/pins
if (hole_rad) if (hole_rad != 0)
{ {
for(int k=0 ; k < vertex_count ; k++) for(int k=0 ; k < vertex_count ; k++)
{ {
@ -97,7 +123,7 @@ make_faces(
vertex_list[(k+1) % vertex_count]->p, vertex_list[(k+1) % vertex_count]->p,
vertex_list[(k+2) % vertex_count]->p vertex_list[(k+2) % vertex_count]->p
); );
printf("translate([%f,%f,0]) cylinder(r=%f,h=%f, center=true, $fs=1);\n", printf("translate([%f,%f,0]) cylinder(r=%f,h=%f, $fs=1);\n",
x, y, x, y,
hole_rad, hole_rad,
hole_height hole_height
@ -121,39 +147,56 @@ main(void)
return EXIT_FAILURE; return EXIT_FAILURE;
const double thickness = 3; const double thickness = 3;
const double inset_dist = 2; const double inset_dist = 2;
const double hole_dist = 7; const double hole_dist = 5;
const double hole_rad = 3.3/2; const double hole_rad = 3.3/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
for(int i = 18 ; i < stl->num_vertex ; i++) for(int i = 0 ; i < stl->num_vertex ; i++)
{ {
const stl_vertex_t * const v = &stl->vertex[i]; const stl_vertex_t * const v = &stl->vertex[i];
const v3_t origin = v->p; const v3_t origin = v->p;
printf("// vertex %d\n" printf("// vertex %d\n"
"//translate([%f,%f,%f])\n" "//translate([%f,%f,%f])\n"
"render() difference()\n"
"{\n" "{\n"
"//sphere(r=%f);\n", "render() difference()\n"
i, origin.p[0], origin.p[1], origin.p[2], thickness/2); "{\n",
i, origin.p[0], origin.p[1], origin.p[2]);
printf("render() intersection() {\n"); avg_x.p[0] = avg_x.p[1] = avg_x.p[2] = 0;
printf("sphere(r=20);\nunion() {\n"); avg_y.p[0] = avg_y.p[1] = avg_y.p[2] = 0;
make_faces(stl, v, 2*thickness, -thickness/2, 0, 0); avg_z.p[0] = avg_z.p[1] = avg_z.p[2] = 0;
printf("}\n");
printf("}\n");
make_faces(stl, v, thickness, inset_dist, hole_dist, hole_rad);
//printf("render() intersection() {\n");
printf("union() {\n");
make_faces(stl, v, thickness, -thickness, 0, 0, 0, 0);
printf("}\n"); printf("}\n");
//printf("}\n");
printf("union() {\n");
// slice away the outer bits
make_faces(stl, v, thickness, 0, -thickness, 0, 0, 0);
//make_faces(stl, v, thickness, inset_dist, hole_dist, hole_rad);
printf("}\n");
printf("} // difference\n");
// add back in the mounting pegs
make_faces(stl, v, 0, 0, 0, hole_dist, hole_rad, thickness);
printf("} // union\n");
break; break;
//if (i == 0) break; // only do one right now //if (i == 0) break; // only do one right now
} }
refframe_t avg;
refframe_init(&avg, avg_x, avg_y, avg_z);
printf("%%");
print_multmatrix(&avg, 1);
//printf("translate([0,0,20]) sphere(r=2);\n");
printf("cube([50,50,50], center=true);\n");
return 0; return 0;
} }

View File

@ -16,4 +16,4 @@ module tetrahedron()
); );
} }
scale(100) tetrahedron(); scale(50) tetrahedron();