/* Bravais Lattice Creator Steven Sahyun University of Wisconsin - Whitewater Physics Department sahyuns@uww.edu January 18, 2016 Creates a model of a crystal unit cell or molcule from a set of orthogonal coordinates Adaptation of code by pmoews found at: http://www.thingiverse.com/thing:12675 Spheres of radius rx are placed at the atomic positions - x0,y0,z0 Bonds are given by the ending and starting positions (x2, y2, z2, x1, y1, z1). //bond( 0.000000, 3.449997, 0.684800, -1.170975, 3.002716, 1.408493); */ //To create a border box support for printing module OpenCube(size, width) { translate([0, 0, 0]) { //first corner rotate([0, 0, 0]){ cube([size, width, width]); cube([width, size, width]); cube([width, width, size]); } } translate([size, size, 0]) { //second corner rotate([0, 0, 180]){ cube([size, width, width]); cube([width, size, width]); cube([width, width, size]); } } translate([size, 0, size]) { //third corner rotate([180, 0, 180]){ cube([size, width, width]); cube([width, size, width]); cube([width, width, size]); } } translate([0, size, size]) { //last corner rotate([180, 0, 0]){ cube([size, width, width]); cube([width, size, width]); cube([width, width, size]); } } } //This puts in an internal grid build support structure, //change the frequency factor and the cube x and y values as needed. module supports(frequency){ for (i = [0:10]) { for (j = [0:10]) { translate([frequency*i , frequency*j, 0]) cube([.2, .2, 10]);//vertical supports translate([0, frequency*j, frequency*i]) cube([10, .2, .2]); // horizontal x supports translate([frequency*i, 0, frequency*j]) cube([.2, 10, .2]); // horizontal y supports } } } //General atom routine module atom(rx, x0,y0,z0){ translate(v=[x0,y0,z0]) sphere(r=rx,$fn=40); } //If want to show bonds module bond(x2,y2,z2,x1,y1,z1){ tx = (x2 + x1)/2; ty = (y2 + y1)/2; tz = (z2 + z1)/2; ax = x2 - x1 ; ay = y2 - y1; az = z2 - z1; translate(v=[tx,ty,tz]) // rotate command by d moews - rotate(a = [-acos(az/sqrt(ax*ax+ay*ay+az*az)), 0, -atan2(ax, ay)]) cylinder(r=.3,h=sqrt(ax*ax+ay*ay+az*az),center=true,$fn=10); } // for Hex lattice structure size is the XY plane size, height in Z module hexagon(size, height) { boxWidth=size/1.75; union() { rotate([0,0,90]) cube([size, boxWidth, height], true); rotate([0,0,150]) cube([size, boxWidth, height], true); rotate([0,0,210]) cube([size, boxWidth, height], true); } } //To print a specific lattice, comment out the rest. //Cubic Bravais Lattice intersection(){ union(){ rx = 5.1; //add 0.2 so atoms are connected in print for (i = [0:1]) { for (j = [0:1]) { for (k = [0:1]) { atom(rx, 10*i, 10*j, 10*k); } } } supports(3.3); } cube(10); //define cubic latice cell } //Body Centered Cubic Bravais Lattice translate([20, 0, 0]) { intersection(){ union(){ //provides structural supports on edges for printing OpenCube(10,0.2); supports(2.4); m = 20; rx = 2.6*sqrt(3); //add 0.1 so atoms are connected in print for (i = [0:1]) { for (j = [0:1]) { for (k = [0:1]) { atom(rx, 10*i, 10*j, 10*k); if (10*i+5