mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-01-16 21:58:26 +01:00
refactor
This commit is contained in:
parent
bcc10201b3
commit
d5dd12ffcd
@ -1,28 +1,30 @@
|
||||
use <polyline_join.scad>;
|
||||
|
||||
function _subdivide(triangles) =
|
||||
[
|
||||
for(tri = triangles)
|
||||
each (tri[0] == "OBTUSE" ? _sub_obtuse(tri[1]) : _sub_acute(tri[1]))
|
||||
let(
|
||||
type = tri[0],
|
||||
a = tri[1],
|
||||
b = tri[2],
|
||||
c = tri[3]
|
||||
)
|
||||
each (type == "OBTUSE" ? _sub_obtuse(a, b, c) : _sub_acute(a, b, c))
|
||||
];
|
||||
|
||||
function _sub_acute(tri_shape) =
|
||||
function _sub_acute(a, b, c) =
|
||||
let(
|
||||
a = tri_shape[0],
|
||||
b = tri_shape[1],
|
||||
c = tri_shape[2],
|
||||
PHI = 1.618033988749895,
|
||||
p = a + (b - a) / PHI
|
||||
)
|
||||
[["ACUTE", [c, p, b]], ["OBTUSE", [p, c, a]]];
|
||||
[["ACUTE", c, p, b], ["OBTUSE", p, c, a]];
|
||||
|
||||
function _sub_obtuse(tri_shape) =
|
||||
function _sub_obtuse(a, b, c) =
|
||||
let(
|
||||
a = tri_shape[0],
|
||||
b = tri_shape[1],
|
||||
c = tri_shape[2],
|
||||
PHI = 1.618033988749895,
|
||||
r = b + (c - b) / PHI
|
||||
)
|
||||
[["OBTUSE", [r, c, a]], each _sub_acute([b, a, r])];
|
||||
[["OBTUSE", r, c, a], each _sub_acute(b, a, r)];
|
||||
|
||||
function _penrose3(triangles, n, i = 0) =
|
||||
i == n ? triangles : _penrose3(_subdivide(triangles), n, i+ 1);
|
||||
@ -31,34 +33,39 @@ function tri2tile(type, tri) =
|
||||
let(
|
||||
tri1 = tri[1],
|
||||
tri2 = tri[2],
|
||||
m = 2 * (tri1 + tri2) / 2 - tri[0]
|
||||
c = (tri1 + tri2) / 2,
|
||||
v = c - tri[0],
|
||||
m = c + v
|
||||
)
|
||||
[[type, tri], [type, [m, tri1, tri2]]];
|
||||
[[type, each tri], [type, m, tri1, tri2]];
|
||||
|
||||
function _zRotation(a) =
|
||||
let(c = cos(a), s = sin(a))
|
||||
[[c, -s], [s, c]];
|
||||
[
|
||||
[c, -s],
|
||||
[s, c]
|
||||
];
|
||||
|
||||
function tile_penrose3(n, triangles) =
|
||||
let(
|
||||
fn = 10,
|
||||
a = 720 / fn
|
||||
a = 720 / fn,
|
||||
tris = _penrose3(
|
||||
is_undef(triangles) ?
|
||||
let(shape_tri0 = [[1, 0], [1, 0] + _zRotation(-180 + a) * [-1, 0], [0, 0]])
|
||||
[
|
||||
for(i = [0:fn / 2 - 1])
|
||||
let(m = _zRotation(i * a), t = [for(p = shape_tri0) m * p])
|
||||
each tri2tile("OBTUSE", t)
|
||||
] :
|
||||
[for(tri = triangles) each tri2tile(tri[0], tri[1])],
|
||||
n
|
||||
)
|
||||
)
|
||||
_penrose3(
|
||||
is_undef(triangles) ?
|
||||
// star
|
||||
let(shape_tri0 = [[1, 0], [1, 0] + _zRotation(-180 + a) * [-1, 0], [0, 0]])
|
||||
[
|
||||
for(i = [0:fn / 2 - 1])
|
||||
let(m = _zRotation(i * a), t = [for(p = shape_tri0) m * p])
|
||||
each tri2tile("OBTUSE", t)
|
||||
] :
|
||||
[for(tri = triangles) each tri2tile(tri[0], tri[1])],
|
||||
n
|
||||
);
|
||||
[for(t = tris) [t[0], [t[3], t[1], t[2]]]];
|
||||
|
||||
use <ptf/ptf_rotate.scad>;
|
||||
use <polyline_join.scad>;
|
||||
use <ptf/ptf_rotate.scad>;
|
||||
|
||||
module draw(tris, radius) {
|
||||
for(t = tris) {
|
||||
@ -74,7 +81,9 @@ module draw(tris, radius) {
|
||||
radius = 10;
|
||||
$fn = 12;
|
||||
|
||||
draw(tile_penrose3(5, [["OBTUSE", [[0, 0], [1, 0], ptf_rotate([1, 0], 108)]]]), radius);
|
||||
draw(tile_penrose3(5, [
|
||||
["OBTUSE", [[0, 0], [2, 0], ptf_rotate([2, 0], 108)]]
|
||||
]), radius);
|
||||
|
||||
translate([40, 0])
|
||||
draw(tile_penrose3(0), radius);
|
||||
|
Loading…
x
Reference in New Issue
Block a user