diff --git a/libtest.png b/libtest.png index 5bde211..06b6c57 100644 Binary files a/libtest.png and b/libtest.png differ diff --git a/readme.md b/readme.md index 641783a..7b28605 100644 --- a/readme.md +++ b/readme.md @@ -3127,8 +3127,12 @@ The "Soft" parameter can be used to determinesif the sheet material needs machin The "Colour" parameter is a quad-array: [R, G, B, Alpha], or can be a named colour, see [OpenSCAD_User_Manual](https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/The_OpenSCAD_Language#color). -For speed sheets should be modelled in 2D by subtracting holes from 2D templates made by ```sheet_2D()``` and then extruded to 3D with ```render_2D_sheet()```. -Note that modules that drill holes will return a 2D object if ```h``` is set to 0 to facilitate this. +For speed sheets should be modelled in 2D by subtracting holes from 2D templates made by `sheet_2D()` and then extruded to 3D with `render_2D_sheet()`. +Note that modules that drill holes will return a 2D object if `h` is set to 0 to facilitate this. + +If 3D features are needed, for example countersinks, then sheets can be modelled in 3D using `sheet()` and then coloured with `render_sheet()`. + +When woven sheets (e.g. carbon fibre) are rendered it is necessary to specify the dimensions again to `render_sheet()` or `render_2D_sheet()`. [vitamins/sheets.scad](vitamins/sheets.scad) Object definitions. @@ -3141,16 +3145,25 @@ Note that modules that drill holes will return a 2D object if ```h``` is set to | Function | Description | |:--- |:--- | | ```sheet_colour(type)``` | Colour | +| ```sheet_colour2(type)``` | Second colour for a woven sheet | | ```sheet_is_soft(type)``` | Is soft enough for wood screws | | ```sheet_thickness(type)``` | Thickness | +| ```sheet_warp(type)``` | Wovern sheet warp | +| ```sheet_weft(type)``` | Wovern sheet weft | + +### Functions +| Function | Description | +|:--- |:--- | +| ```sheet_is_woven(type)``` | Is a woven sheet, eg carbon fiber | ### Modules | Module | Description | |:--- |:--- | -| ```render_2D_sheet(type, colour = false)``` | Extrude a 2D sheet template and give it the correct colour | -| ```render_sheet(type, colour = false)``` | Render a sheet in the correct colour after holes have been subtracted | +| ```render_2D_sheet(type, colour = false, colour2 = false, w = undef, d = undef)``` | Extrude a 2D sheet template and give it the correct colour | +| ```render_sheet(type, colour = false, colour2 = false, w = undef, d = undef)``` | Render a sheet in the correct colour after holes have been subtracted | | ```sheet(type, w, d, corners = [0, 0, 0, 0])``` | Draw specified sheet | | ```sheet_2D(type, w, d, corners = [0, 0, 0, 0])``` | 2D sheet template with specified size and optionally rounded corners | +| ```woven_sheet(type, thickness, colour, colour2, w, d)``` | Create a woven 2D sheet with specified thickness and colours | ![sheets](tests/png/sheets.png) @@ -3173,6 +3186,9 @@ Note that modules that drill holes will return a 2D object if ```h``` is set to | 1 | ```sheet(PMMA3, 30, 30, 2)``` | Sheet acrylic 30mm x 30mm x 3mm | | 1 | ```sheet(PMMA6, 30, 30, 2)``` | Sheet acrylic 30mm x 30mm x 6mm | | 1 | ```sheet(PMMA8, 30, 30, 2)``` | Sheet acrylic 30mm x 30mm x 8mm | +| 2 | ```sheet(CF1, 30, 30, 2)``` | Sheet carbon fiber 30mm x 30mm x 1mm | +| 2 | ```sheet(CF2, 30, 30, 2)``` | Sheet carbon fiber 30mm x 30mm x 2mm | +| 2 | ```sheet(CF3, 30, 30, 2)``` | Sheet carbon fiber 30mm x 30mm x 3mm | | 1 | ```sheet(glass2, 30, 30, 2)``` | Sheet glass 30mm x 30mm x 2mm | | 1 | ```sheet(Steel06, 30, 30, 2)``` | Sheet mild steel 30mm x 30mm x 0.6mm | diff --git a/tests/png/sheets.png b/tests/png/sheets.png index fe69bdd..2eaa377 100644 Binary files a/tests/png/sheets.png and b/tests/png/sheets.png differ diff --git a/tests/sheets.scad b/tests/sheets.scad index fcf1e08..77b0e7e 100644 --- a/tests/sheets.scad +++ b/tests/sheets.scad @@ -20,32 +20,30 @@ include <../utils/core/core.scad> use <../utils/layout.scad> include <../vitamins/sheets.scad> +include <../vitamins/screws.scad> width = 30; +2d = true; module sheets() layout([for(s = sheets) width], 5) - render_sheet(sheets[$i]) sheet(sheets[$i], width, width, 2); + let(sheet = sheets[$i], w = sheet_is_woven(sheet) ? width : undef) + if(2d) + render_2D_sheet(sheet, w = w, d = w) + difference() { + sheet_2D(sheet, width, width, 2); -module test2() { - render_sheet(CF3) sheet(CF3, width, width, 2); - translate([40,0,0]) - render_2D_sheet(CF3) sheet_2D(CF3, width, width, 2); - translate([80,0,0]) - sheet(CF3, width, width, 2); - translate([120,0,0]) - sheet_2D(CF3, width, width, 2); + circle(3); + } + else + render_sheet(sheet, w = w, d = w) + difference() { + sheet(sheet, width, width, 2); + + translate_z(sheet_thickness(sheet) / 2) + screw_countersink(M3_cs_cap_screw); + } - translate([160,0,0]) - render_sheet(MDF6) sheet(MDF6, width, width, 2); - translate([200,0,0]) - render_2D_sheet(MDF6) sheet_2D(MDF6, width, width, 2); - translate([240,0,0]) - sheet(MDF6, width, width, 2); - translate([280,0,0]) - sheet_2D(MDF6, width, width, 2); -} if($preview) sheets(); - //test2(); diff --git a/vitamins/sheet.scad b/vitamins/sheet.scad index a433cbc..3646398 100644 --- a/vitamins/sheet.scad +++ b/vitamins/sheet.scad @@ -27,8 +27,12 @@ //! //! The "Colour" parameter is a quad-array: [R, G, B, Alpha], or can be a named colour, see [OpenSCAD_User_Manual](https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/The_OpenSCAD_Language#color). //! -//! For speed sheets should be modelled in 2D by subtracting holes from 2D templates made by ```sheet_2D()``` and then extruded to 3D with ```render_2D_sheet()```. -//! Note that modules that drill holes will return a 2D object if ```h``` is set to 0 to facilitate this. +//! For speed sheets should be modelled in 2D by subtracting holes from 2D templates made by `sheet_2D()` and then extruded to 3D with `render_2D_sheet()`. +//! Note that modules that drill holes will return a 2D object if `h` is set to 0 to facilitate this. +//! +//! If 3D features are needed, for example countersinks, then sheets can be modelled in 3D using `sheet()` and then coloured with `render_sheet()`. +//! +//! When woven sheets (e.g. carbon fibre) are rendered it is necessary to specify the dimensions again to `render_sheet()` or `render_2D_sheet()`. // include <../utils/core/core.scad> @@ -36,7 +40,9 @@ function sheet_thickness(type) = type[2]; //! Thickness function sheet_colour(type) = type[3]; //! Colour function sheet_is_soft(type) = type[4]; //! Is soft enough for wood screws function sheet_is_woven(type) = !is_undef(type[5]); //! Is a woven sheet, eg carbon fiber -function sheet_colour2(type) = is_undef(type[7]) ? sheet_colour(type) * 0.8 : type[7]; //! Second colour for a woven sheet +function sheet_warp(type) = type[5]; //! Wovern sheet warp +function sheet_weft(type) = type[6]; //! Wovern sheet weft +function sheet_colour2(type) = type[7]; //! Second colour for a woven sheet module corner(r) { if(r > 0) @@ -52,7 +58,10 @@ module corner(r) { square(1, center = true); } -module corner_hull(w, d, corners) { +module sheet_2D(type, w, d, corners = [0, 0, 0, 0]) { //! 2D sheet template with specified size and optionally rounded corners + t = sheet_thickness(type); + vitamin(str("sheet(", type[0], ", ", w, ", ", d, arg(corners, [0, 0, 0, 0]), "): ", type[1], " ", round(w), "mm x ", round(d), "mm x ", t, "mm")); + c = is_list(corners) ? corners : corners * [1, 1, 1, 1]; hull() { @@ -73,108 +82,73 @@ module corner_hull(w, d, corners) { } } -module sheet_2D(type, w, d, corners = [0, 0, 0, 0]) { //! 2D sheet template with specified size and optionally rounded corners - t = sheet_thickness(type); - vitamin(str("sheet(", type[0], ", ", w, ", ", d, arg(corners, [0, 0, 0, 0]), "): ", type[1], " ", round(w), "mm x ", round(d), "mm x ", t, "mm")); - - if (sheet_is_woven(type)) { - if (is_undef($sheet_woven_positive)) { - // not being called from within render_2D_sheet, so do both colours - color(sheet_colour(type)) - let($sheet_woven_positive = true) - woven_sheet_2D(type, w, d, corners); - color(sheet_colour2(type)) - let($sheet_woven_positive = false) - woven_sheet_2D(type, w, d, corners); - } else { - // being called from within render_2D_sheet - woven_sheet_2D(type, w, d, corners); - } - } else { - color(sheet_colour(type)) - corner_hull(w, d, corners); - } -} - module sheet(type, w, d, corners = [0, 0, 0, 0]) //! Draw specified sheet - if (sheet_is_woven(type) && is_undef($sheet_woven_positive)) { - // not being called from within render_3D_sheet, so do both colours - color(sheet_colour(type)) - linear_extrude(sheet_thickness(type), center = true) - let($sheet_woven_positive = true) - woven_sheet_2D(type, w, d, corners); - color(sheet_colour2(type)) - linear_extrude(sheet_thickness(type), center = true) - let($sheet_woven_positive = false) - woven_sheet_2D(type, w, d, corners); - } else { - color(sheet_colour(type)) - linear_extrude(sheet_thickness(type), center = true) - sheet_2D(type, w, d, corners); - } + linear_extrude(sheet_thickness(type), center = true) + sheet_2D(type, w, d, corners); - -module render_sheet(type, colour = false, colour2 = false) { //! Render a sheet in the correct colour after holes have been subtracted - color(colour ? colour : sheet_colour(type)) +module render_sheet(type, colour = false, colour2 = false, w = undef, d = undef) { //! Render a sheet in the correct colour after holes have been subtracted + woven = sheet_is_woven(type); + t = sheet_thickness(type); + colour = colour ? colour : sheet_colour(type); + colour2 = colour2 ? colour2 : sheet_colour2(type); + color(woven ? colour2 : colour) render() - let($sheet_woven_positive = true) + scale([1, 1, woven ? (t - 2 * eps) / t : 1]) children(); - if (sheet_is_woven(type)) - color(colour2 ? colour2 : sheet_colour2(type)) - render() - let($sheet_woven_positive = false) - children(); + if(woven) + for(side = [-1, 1], z = side * (t - eps) / 2) + translate_z(z) + woven_sheet(type, eps, colour, colour2, w, d) + projection(cut = true) + translate_z(-z) + children(); } -module render_2D_sheet(type, colour = false, colour2 = false) { //! Extrude a 2D sheet template and give it the correct colour - let($dxf_colour = colour ? colour : sheet_colour(type)) - color($dxf_colour) - let($sheet_woven_positive = true) - linear_extrude(sheet_thickness(type), center = true) - children(); - - if (sheet_is_woven(type)) - color(colour2 ? colour2 : sheet_colour2(type)) - let($sheet_woven_positive = false) +module render_2D_sheet(type, colour = false, colour2 = false, w = undef, d = undef) { //! Extrude a 2D sheet template and give it the correct colour + colour = colour ? colour : sheet_colour(type); + colour2 = colour2 ? colour2 : sheet_colour2(type); + let($dxf_colour = colour) + if(sheet_is_woven(type)) + woven_sheet(type, sheet_thickness(type), colour, colour2, w, d) + children(); + else + color($dxf_colour) linear_extrude(sheet_thickness(type), center = true) children(); } -module woven_sheet_2D(type, w, d, corners = [0, 0, 0, 0], warp = 2, weft) {//! Create a woven 2D sheet with specified size, colours, warp and weft - size = [w, d]; +module woven_sheet(type, thickness, colour, colour2, w, d) {//! Create a woven 2D sheet with specified thickness and colours + ; + warp = sheet_warp(type); + weft = sheet_weft(type); + warp_doublet_count = assert(!is_undef(w) && !is_undef(d), "Must specify the dimensions to render woven sheets") ceil(w / (2 * warp)); + weft_count = ceil(d / weft); - weft = weft ? weft : warp; - warp_doublet_count = floor(size.x / (2 * warp)) + 1; + module chequerboard(odd = 0) + translate([-w / 2, -d / 2]) + for (y = [0 : weft_count - 1], x = [0 : warp_doublet_count - 1]) + translate([warp * (2 * x + ((y + odd) % 2)), weft * y]) + square([warp, weft]); - module layer(weft) { - for (x = [0 : warp_doublet_count - 1]) - translate([2 * x * warp, 0, 0]) - square([warp, weft]); - } - - module positive() { - intersection() { - translate([-size.x / 2, -size.y / 2]) { - weft_count = floor(size.y / weft) + 1; - for (y = [0 : weft_count - 1]) - translate([warp * (y % 2), weft * y, 0]) - layer(weft); - } - corner_hull(w, d, corners); - } - } - - module negative() { + module negative() difference() { - corner_hull(size.x, size.y, corners); + square(size, center = true); positive(); } - } - if (is_undef($sheet_woven_positive) || $sheet_woven_positive==true) - positive(); - else - negative(); + color(colour) + linear_extrude(thickness) + intersection() { + chequerboard(); + children(); + } + + if(thickness > eps) + color(colour2) + linear_extrude(thickness) + intersection() { + chequerboard(1); + children(); + } } - diff --git a/vitamins/sheets.scad b/vitamins/sheets.scad index 6cff95d..171e103 100644 --- a/vitamins/sheets.scad +++ b/vitamins/sheets.scad @@ -50,6 +50,6 @@ CF2 = [ "CF2", "Sheet carbon fiber", 2, grey(30), CF3 = [ "CF3", "Sheet carbon fiber", 3, grey(30), false, 2, 2, grey(25)]; -sheets = [MDF6, MDF10, MDF12, MDF19, PMMA2, PMMA3, PMMA6, PMMA8, PMMA10, glass2, DiBond, DiBond6, Cardboard, FoilTape, Foam20, AL6, AL8, Steel06, CF1, CF2, CF3]; +sheets = [CF1, CF2, CF3, MDF6, MDF10, MDF12, MDF19, PMMA2, PMMA3, PMMA6, PMMA8, PMMA10, glass2, DiBond, DiBond6, Cardboard, FoilTape, Foam20, AL6, AL8, Steel06]; use