1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-09-01 18:54:39 +02:00
This commit is contained in:
Justin Lin
2021-08-11 08:28:57 +08:00
parent 26a0d7a62e
commit d350362c47

View File

@@ -1,12 +1,7 @@
use <ptf/ptf_rotate.scad>; use <ptf/ptf_rotate.scad>;
use <hull_polyline2d.scad>; use <hull_polyline2d.scad>;
module tile_penrose3(radius, fn, n) { function _subdivide(triangles) =
// triangle: [type, pa, pb pc], c: false(36) or true(108)
PHI = 1.618033988749895; // golden ratio
function _subdivide(triangles) =
[ [
for(tri = triangles) for(tri = triangles)
let( let(
@@ -18,56 +13,63 @@ module tile_penrose3(radius, fn, n) {
each (type ? _sub_a1(a, b, c) : _sub_a0(a, b, c)) each (type ? _sub_a1(a, b, c) : _sub_a0(a, b, c))
]; ];
function _sub_a0(a, b, c) = function _sub_a0(a, b, c) =
let(p = a + (b - a) / PHI) let(
PHI = 1.618033988749895,
p = a + (b - a) / PHI
)
[[false, c, p, b], [true, p, c, a]]; [[false, c, p, b], [true, p, c, a]];
function _sub_a1(a, b, c) = function _sub_a1(a, b, c) =
let( let(
PHI = 1.618033988749895,
q = b + (a - b) / PHI, q = b + (a - b) / PHI,
r = b + (c - b) / PHI r = b + (c - b) / PHI
) )
[[true, r, c, a], [true, q, r, b], [false, r, q, a]]; [[true, r, c, a], [true, q, r, b], [false, r, q, a]];
function _penrose3(triangles, n, i = 0) = function _penrose3(triangles, n, i = 0) =
i == n ? triangles : i == n ? triangles :
_penrose3(_subdivide(triangles), n, i+ 1); _penrose3(_subdivide(triangles), n, i+ 1);
function tile_penrose3(n) =
a0 = 360 / fn; let(
a2 = 180 - a0 * 2; a0 = 360 / $fn,
a2 = 180 - a0 * 2,
shape_tri0 = [[0, 0], [radius, 0], ptf_rotate([radius, 0], a0)]; shape_tri0 = [[0, 0], [1, 0], ptf_rotate([1, 0], a0)]
triangles = [ )
for(i = [0:fn - 1]) _penrose3([
for(i = [0:$fn - 1])
let(t = [for(p = shape_tri0) ptf_rotate(p, i * a0)]) let(t = [for(p = shape_tri0) ptf_rotate(p, i * a0)])
i % 2 == 0 ? [false, t[0], t[1], t[2]] : [false, t[0], t[2], t[1]] i % 2 == 0 ? [false, t[0], t[1], t[2]] : [false, t[0], t[2], t[1]]
]; ], n);
tris = _penrose3(triangles, n);
module draw(tris) {
for(t = tris) { for(t = tris) {
color(t[0] ? "white" : "black") color(t[0] ? "white" : "black")
linear_extrude(.5))
polygon([t[2], t[1], t[3]]); polygon([t[2], t[1], t[3]]);
linear_extrude(1) linear_extrude(1)
hull_polyline2d([t[2], t[1], t[3]], .2); hull_polyline2d([t[2], t[1], t[3]], .1);
} }
} }
radius = 10; radius = 10;
fn = 12; $fn = 12;
tile_penrose3(radius, fn, 0); draw(tile_penrose3(0) * radius);
translate([30, 0]) translate([30, 0])
tile_penrose3(radius, fn, 1); draw(tile_penrose3(1) * radius);
translate([60, 0]) translate([60, 0])
tile_penrose3(radius, fn, 2); draw(tile_penrose3(2) * radius);
translate([0, -30]) translate([0, -30])
tile_penrose3(radius, fn, 3); draw(tile_penrose3(3) * radius);
translate([30, -30]) translate([30, -30])
tile_penrose3(radius, fn, 4); draw(tile_penrose3(4) * radius);
translate([60, -30]) translate([60, -30])
tile_penrose3(radius, fn, 5); draw(tile_penrose3(5) * radius);