# 從曲線到曲面

March 9, 2022

``````use <surface/sf_thicken.scad>

function f(x, y) = (y ^ 2) / 4 - (x ^ 2) / 4;

min_value = -3;
max_value = 3;
resolution = 0.5;
thickness = 0.5;

points = [
for(y = [min_value:resolution:max_value])
[
for(x = [min_value:resolution:max_value])
[x, y, f(x, y)]
]
];

sf_thicken(points, thickness);
``````

## 談談貝茲曲面

``````use <surface/sf_thicken.scad>
use <bezier_curve.scad>
use <polyline_join.scad>

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]]
];

thickness = 2;
t_step = 0.05;

points = [for(i = [0:len(ctrl_pts) - 1])
bezier_curve(t_step, ctrl_pts[i])
];

sf_thicken(points, thickness);

// 顯示四條貝茲曲線
#for(curve = points) {
polyline_join(curve)
sphere(3);
}
``````

## 使用 sf_splines 函式

dotSCAD 提供了 `sf_splines`，可以指定列與行方向的曲線函式，如果只指定一個曲線函式，那麼列與行會使用同一個曲線函式。

``````use <surface/sf_thicken.scad>
use <surface/sf_splines.scad>
use <bezier_curve.scad>

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]]
];

thickness = 2;
t_step = 0.05;

bezier = function(points) bezier_curve(t_step, points);
points = sf_splines(ctrl_pts, bezier);

sf_thicken(points, thickness);
``````

``````use <surface/sf_thicken.scad>
use <surface/sf_splines.scad>
use <curve.scad>

ctrl_pts = [
[[0, 0, 20],  [60, 0, 35],   [90, 0, 40],   [150, 0, 35],   [200, 0, 10]],
[[0, 50, 30], [60, 60, 25],  [100, 50, 50], [150, 50, 35],   [200, 50, 10]],
[[0, 100, 0], [60, 100, 35], [90, 100, 40], [150, 100, 45], [200, 100, 10]],
[[0, 150, 0], [60, 150, 35], [90, 135, 45], [150, 135, 55], [200, 120, 10]],
[[0, 155, 0], [60, 155, 35], [90, 155, 50], [150, 155, 65], [200, 155, 10]]
];

thickness = 2;
t_step = 0.05;

points = sf_splines(ctrl_pts, function(points) curve(t_step, points));

sf_thicken(points, thickness);
``````

## 關於 Golden Taiwan

dotSCAD 有一些 _extrude 模組，可以指定形狀的座標資訊來實現擠出，黃金螺旋的臺灣，是基於 `golden_spiral_extrude` 模組與 `shape_taiwan` 產生：

``````use <shape_taiwan.scad>
use <golden_spiral_extrude.scad>

mirror_taiwan = [for(pt = shape_taiwan(15)) [pt.x * -1, pt.y]];

golden_spiral_extrude(
mirror_taiwan,
from = 1,
to = 10,
point_distance = 2.5,
scale = 10
);
``````

``````use <shape_taiwan.scad>
use <helix_extrude.scad>

r1 = 15;
r2 = 100;
levels = 3;
level_dist = 50;

helix_extrude(shape_taiwan(80),
radius = [r1, r2],
levels = levels,
level_dist = level_dist,
vt_dir = "SPI_DOWN",
rt_dir = "CLK",
scale = 0.1
);
``````