1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-01-16 21:58:26 +01:00

added hexagons

This commit is contained in:
Justin Lin 2017-04-11 15:38:35 +08:00
parent 2308ce5817
commit bede5927ad
6 changed files with 94 additions and 84 deletions

View File

@ -26,6 +26,7 @@ Some modules may depend on other modules. For example, the `polyline2d` module d
- [polyline2d](https://openhome.cc/eGossip/OpenSCAD/lib-polyline2d.html)
- [circular_sector](https://openhome.cc/eGossip/OpenSCAD/lib-circular_sector.html)
- [arc](https://openhome.cc/eGossip/OpenSCAD/lib-arc.html)
- [hexagons](https://openhome.cc/eGossip/OpenSCAD/lib-hexagons.html)
- 3D
- [line3d](https://openhome.cc/eGossip/OpenSCAD/lib-line3d.html)

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

32
docs/lib-hexagons.md Normal file
View File

@ -0,0 +1,32 @@
# hexagons
A hexagonal structure is useful in many situations. This module creates hexagons in a hexagon.
## Parameters
- `radius` : The radius of every hexagon.
- `spacing` : The length of the gap between hexagons.
- `levels` : How many levels if counting from the center?
## Examples
include <hexagons.scad>;
radius = 20;
spacing = 2;
levels = 2;
hexagons(radius, spacing, levels);
![hexagons](images/lib-hexagons-1.JPG)
include <hexagons.scad>;
radius = 20;
spacing = 2;
levels = 3;
hexagons(radius, spacing, levels);
![hexagons](images/lib-hexagons-2.JPG)

56
src/hexagons.scad Normal file
View File

@ -0,0 +1,56 @@
/**
* hexagons.scad
*
* Creates hexagons in a hexagon.
*
* @copyright Justin Lin, 2017
* @license https://opensource.org/licenses/lgpl-3.0.html
*
* @see https://openhome.cc/eGossip/OpenSCAD/lib-hexagons.html
*
**/
radius = 20;
levels = 3;
spacing = 2;
thickness = 20;
module hexagons(radius, spacing, levels) {
beginning_n = 2 * levels - 1;
offset_x = radius * cos(30);
offset_y = radius + radius * sin(30);
module hexagon() {
rotate(30)
offset(r = -spacing / 2)
circle(radius, $fn = 6);
}
module line_hexagons(n) {
offset = 2 * offset_x;
for(i = [0:n - 1]) {
offset_p = [i * offset, 0, 0];
translate(offset_p)
hexagon();
}
}
translate([2 * (offset_x - offset_x * levels) , 0, 0])
union() {
line_hexagons(beginning_n);
if(levels > 1) {
for(i = [1:beginning_n - (levels)]) {
translate([offset_x * i, offset_y * i, 0])
line_hexagons(beginning_n - i);
mirror([0, 1, 0])
translate([offset_x * i, offset_y * i, 0])
line_hexagons(beginning_n - i);
}
}
}
}
linear_extrude(thickness)
hexagons(radius, spacing, levels);

View File

@ -1,87 +1,8 @@
include <line3d.scad>;
include <polyline3d.scad>;
include <bezier_curve.scad>;
include <bezier_surface.scad>;
include <function_grapher.scad>;
include <hexagons.scad>;
t_step = 0.05;
thickness = 0.5;
radius = 20;
spacing = 2;
levels = 3;
ctrl_pts = [
[[0, 0, 20], [60, 0, -35], [90, 0, 60], [200, 0, 5]],
[[0, 50, 30], [100, 60, -25], [120, 50, 120], [200, 50, 5]],
[[0, 100, 0], [60, 120, 35], [90, 100, 60], [200, 100, 45]],
[[0, 150, 0], [60, 150, -35], [90, 180, 60], [200, 150, 45]]
];
g = bezier_surface(t_step, ctrl_pts);
color("yellow") function_grapher(g, thickness);
width = 2;
demo = "YES";
ani = "YES";
if(demo == "YES") {
width = 2;
r = 3;
pts = [
for(i = [0:len(ctrl_pts) - 1])
bezier_curve(t_step, ctrl_pts[i])
];
if(ani == "YES") {
// first bezier curve
for(i = [0:len(ctrl_pts) - 1]) {
color("green") union() {
for(j = [0:len(ctrl_pts[i]) - 1]) {
translate(ctrl_pts[i][j])
sphere(r = r);
}
for(j = [0:len(ctrl_pts[i]) - 1]) {
polyline3d(
ctrl_pts[i]
, width);
}
}
color("red")
polyline3d(
bezier_curve(t_step, ctrl_pts[i]), width
);
}
step = len(g[0]);
echo(step);
// second bezier curve
ctrl_pts2 = [for(i = [0:len(pts) - 1]) pts[i][$t * step]];
color("blue") union() {
for(pt = ctrl_pts2) {
translate(pt)
sphere(r = r);
}
polyline3d(ctrl_pts2, width);
}
color("black")
polyline3d(g[$t * step], width);
} else {
// first bezier curve
for(i = [0:len(ctrl_pts) - 1]) {
color("green") union() {
for(j = [0:len(ctrl_pts[i]) - 1]) {
translate(ctrl_pts[i][j])
sphere(r = r);
}
}
}
color("green") function_grapher(ctrl_pts, width, style = "LINES");
}
}
hexagons(radius, spacing, levels);