scaddy/wireframe.scad
Tony Tkacik 549011c078 Experimental functionality
Signed-off-by: Tony Tkacik <tonydamage@gmail.com>
2019-02-23 20:26:37 +01:00

48 lines
1.2 KiB
OpenSCAD

module _rod(a, b, r) {
translate(a) sphere(r=r);
translate(b) sphere(r=r);
dir = b-a;
h = norm(dir);
if(dir[0] == 0 && dir[1] == 0) {
// no transformation necessary
cylinder(r=r, h=h);
}
else {
w = dir / h;
u0 = cross(w, [0,0,1]);
u = u0 / norm(u0);
v0 = cross(w, u);
v = v0 / norm(v0);
multmatrix(m=[[u[0], v[0], w[0], a[0]],
[u[1], v[1], w[1], a[1]],
[u[2], v[2], w[2], a[2]],
[0, 0, 0, 1]])
cylinder(r=r, h=h);
}
}
module outline(points3,r=0.5) {
p=len(points3);
for(start = [0:1:p-1]) {
stop=(start+1)%p;
a = points3[start];
b = points3[stop];
// FIXME: Do not repeat points
echo(a,b);
_rod(a,b,r);
}
}
module wireframe(points3,polygons,r=0.5) {
for(p=polygons) {
for(set = [0:1:len(p)-1]) {
a = points3[p[set]];
b = points3[p[(set+1)%len(p)]];
// FIXME: Do not repeat points
echo(p[set],p[(set+1)%len(p)],a,b);
_rod(a,b,r);
}
}
}