Revert "Add top level readme, rename single_plate"
[clinton/prusa3.git] / single_plate / src / inc / roundCornersCube.scad
1 /*
2 http://codeviewer.org/view/code:1b36
3 Copyright (C) 2011 Sergio Vilches
4 This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
5 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
6 Contact: s.vilches.e@gmail.com
7
8
9 -----------------------------------------------------------
10 Round Corners Cube (Extruded)
11 roundCornersCube(x,y,z,r) Where:
12 - x = Xdir width
13 - y = Ydir width
14 - z = Height of the cube
15 - r = Rounding radious
16
17 Example: roundCornerCube(10,10,2,1);
18 *Some times it's needed to use F6 to see good results!
19 -----------------------------------------------------------
20 */
21 // Test it!
22 // roundCornersCube(10,5,2,1);
23
24
25 module createMeniscus(h,radius) // This module creates the shape that needs to be substracted from a cube to make its corners rounded.
26 difference(){ //This shape is basicly the difference between a quarter of cylinder and a cube
27 translate([radius/2+0.1,radius/2+0.1,0]){
28 cube([radius+0.2,radius+0.1,h+0.2],center=true); // All that 0.x numbers are to avoid "ghost boundaries" when substracting
29 }
30
31 cylinder(h=h+0.2,r=radius,$fn = 25,center=true);
32 }
33
34
35 module roundCornersCube(x,y,z,r) // Now we just substract the shape we have created in the four corners
36 difference(){
37 cube([x,y,z], center=true);
38
39 translate([x/2-r,y/2-r]){ // We move to the first corner (x,y)
40 rotate(0){
41 createMeniscus(z,r); // And substract the meniscus
42 }
43 }
44 translate([-x/2+r,y/2-r]){ // To the second corner (-x,y)
45 rotate(90){
46 createMeniscus(z,r); // But this time we have to rotate the meniscus 90 deg
47 }
48 }
49 translate([-x/2+r,-y/2+r]){ // ...
50 rotate(180){
51 createMeniscus(z,r);
52 }
53 }
54 translate([x/2-r,-y/2+r]){
55 rotate(270){
56 createMeniscus(z,r);
57 }
58 }
59 }
60
61
62
63
64