1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-02-24 17:42:44 +01:00
dotSCAD/docs/lib-voronoi2d.md

47 lines
1.4 KiB
Markdown
Raw Normal View History

2019-06-07 17:46:17 +08:00
# voronoi2d
2019-06-01 19:58:08 +08:00
Creats a [Voronoi diagram](https://en.wikipedia.org/wiki/Voronoi_diagram). The initial region for each cell is calculated automatically from the given points by the following code:
xs = [for(p = points) p[0]];
ys = [for(p = points) abs(p[1])];
region_size = max([(max(xs) - min(xs) / 2), (max(ys) - min(ys)) / 2]);
**Since:** 1.3.
## Parameters
- `points` : Points for each cell.
- `spacing` : Distance between cells. Default to 1.
- `r`, `delta`, `chamfer` : The outlines of each cell can be moved outward or inward. These parameters have the same effect as [`offset`](https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Transformations#offset).
- `region_type` : The initial shape for each cell can be `"square"` or `"circle"`. Default to `"square"`.
## Examples
2019-06-07 17:46:17 +08:00
include <voronoi2d.scad>;
2019-06-01 19:58:08 +08:00
xs = rands(-20, 20, 50);
ys = rands(-20, 20, 50);
points = [for(i = [0:len(xs) - 1]) [xs[i], ys[i]]];
2019-06-07 17:46:17 +08:00
voronoi2d(points);
2019-06-01 19:58:08 +08:00
translate([60, 0, 0])
voronoi(points, region_type = "circle");
2019-06-07 17:46:17 +08:00
![voronoi2d](images/lib-voronoi2d-1.JPG)
2019-06-01 19:58:08 +08:00
2019-06-07 17:46:17 +08:00
include <voronoi2d.scad>;
2019-06-01 19:58:08 +08:00
include <hollow_out.scad>;
xs = rands(0, 40, 50);
ys = rands(0, 20, 50);
points = [for(i = [0:len(xs) - 1]) [xs[i], ys[i]]];
difference() {
square([40, 20]);
2019-06-07 17:46:17 +08:00
voronoi2d(points);
2019-06-01 19:58:08 +08:00
}
hollow_out(shell_thickness = 1) square([40, 20]);
2019-06-07 17:46:17 +08:00
![voronoi2d](images/lib-voronoi2d-2.JPG)