# 黃金螺線

March 7, 2022

## 使用公式繪製

``````use <polyline_join.scad>

phi = (1 + sqrt(5)) / 2;
degrees = 720;

points = [
for(d = [0:degrees])
let(
r = pow(phi, theta * 2 / PI)
)
r * [cos(d), sin(d)]
];

polyline_join(points)
circle(1);
``````

## 費氏數列

``````use <polyline_join.scad>

module golden_rectangle(from, to, base_width, line_width) {
if(from <= to) {
fibs = fibseq(from, from + 1);
r = base_width * fibs[0];

// 90 度弧線
angle = 90,
width = line_width,
width_mode = "LINE_INWARD"
);

// 正方形
sq_shape = shape_square(r);
translate([r, r] / 2)
polyline_join([each sq_shape, sq_shape[0]])
circle(line_width / 2);

diff = fibs[1] - fibs[0];

translate([0, -diff * base_width])
rotate(90)
golden_rectangle(from + 1, to, base_width, line_width);
}
}

\$fn = 24;

from = 1;
to = 6;
base_width = 5;
line_width = 2;

linear_extrude(line_width)
golden_rectangle(from, to, base_width, line_width);
``````

dotSCAD 的 `fibseq` 可以生成第 `from` 個到第 `to` 個費氏數列，畫出來的模型如下：

``````use <golden_spiral.scad>

pts_angles = golden_spiral(
from = 3,
to = 10,
point_distance = 1
);

for(pt_angle = pts_angles) {
translate(pt_angle[0])
sphere(0.5);
}
``````

``````use <polyline_join.scad>

// 黃金矩形
module golden_rectangle(from, to, base_width, line_width) {
if(from <= to) {
fibs = fibseq(from, from + 1);
r = base_width * fibs[0];

sq_shape = shape_square(r);
translate([r, r] / 2)
polyline_join([each sq_shape, sq_shape[0]])
circle(line_width / 2);

diff = fibs[1] - fibs[0];

translate([0, -diff * base_width])
rotate(90)
golden_rectangle(from + 1, to, base_width, line_width);
}
else {
// 最後畫個小環
fibs = fibseq(from - 1, from);
diff = fibs[1] - fibs[0];
r = base_width * fibs[0];

ring_r = r / 8;

offset_p = [-r / 2, -diff * base_width - (r + ring_r) + line_width * 0.5];
rotate(90)
translate(offset_p)
hollow_out(line_width)
circle(ring_r);
}
}

// 黃金螺線
module golden_spiral(from, to, base_width, line_width, point_distance) {
pts_angles = golden_spiral(
from = from,
to = to,
point_distance = point_distance
);

points = [for(pt_angle = pts_angles) pt_angle[0]] * base_width;

polyline_join(points)
circle(line_width / 2);
}

\$fn = 24;

from = 1;
to = 5;
base_width = 5;
line_width = 1.25;
point_distance = .5;

linear_extrude(line_width * 2) {
golden_rectangle(from, to, base_width, yline_width);
golden_spiral(from, to, base_width, line_width, point_distance);
}
``````