diff --git a/README.md b/README.md index 4e9fd448..94173782 100644 --- a/README.md +++ b/README.md @@ -356,7 +356,7 @@ These examples incubate dotSCAD and dotSCAD refactors these examples. See [examp Signature | Description --|-- [**surface/sf_curve**(levels, curve_path, ...)](https://openhome.cc/eGossip/OpenSCAD/lib3x-sf_curve.html) | curve a photo. -**surface/sf_splines**(ctrl_pts, row_spline, column_spline) | generalized-spline surface. +[**surface/sf_splines**(ctrl_pts, row_spline, column_spline)](https://openhome.cc/eGossip/OpenSCAD/lib3x-sf_splines.html) | generalized-spline surface. ## Triangle diff --git a/docs/images/lib3x-sf_splines-1.JPG b/docs/images/lib3x-sf_splines-1.JPG new file mode 100644 index 00000000..87b6f53c Binary files /dev/null and b/docs/images/lib3x-sf_splines-1.JPG differ diff --git a/docs/lib3x-sf_splines.md b/docs/lib3x-sf_splines.md new file mode 100644 index 00000000..74e69ee7 --- /dev/null +++ b/docs/lib3x-sf_splines.md @@ -0,0 +1,62 @@ +# sf_splines + +Given a set of control points and spline functions, the `sf_splines` function returns surface points. + +**Since:** 3.1 + +## Parameters + +- `ctrl_pts` : A set of control points. See examples below. +- `row_spline` : The spline function for row points. +- `column_spline` : The spline function for columns points. Default to `row_spline`. + +## Examples + +If you want to make a bezier surface: + + use ; + use ; + use ; + + 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); + + function_grapher(sf_splines(ctrl_pts, bezier), thickness); + +![sf_splines](images/lib3x-sf_splines-1.JPG) + +The following figure shows controll points and bazier curves around the surface. + +![sf_splines](images/lib3x-sf_splines-2.JPG) + +If you want to make a bspline surface: + + use ; + use ; + use ; + + 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; + degrees = 2; + + bspline = function(points) bspline_curve(t_step, degrees, points); + + function_grapher(sf_splines(ctrl_pts, bspline), thickness); + +![sf_splines](images/lib3x-sf_splines-3.JPG) \ No newline at end of file diff --git a/src/surface/sf_splines.scad b/src/surface/sf_splines.scad index e3b5e95d..4a4108f7 100644 --- a/src/surface/sf_splines.scad +++ b/src/surface/sf_splines.scad @@ -1,3 +1,13 @@ +/** +* sf_splines.scad +* +* @copyright Justin Lin, 2021 +* @license https://opensource.org/licenses/lgpl-3.0.html +* +* @see https://openhome.cc/eGossip/OpenSCAD/lib3x-sf_splines.html +* +**/ + function sf_splines(ctrl_pts, row_spline, column_spline) = let( leng_ctrl_pts = len(ctrl_pts), @@ -12,79 +22,4 @@ function sf_splines(ctrl_pts, row_spline, column_spline) = [ for(c = 0; c < leng_r_pts0; c = c + 1) cspline([for(r = 0; r < leng_r_pts; r = r + 1) r_pts[r][c]]) - ]; - -/* -use ; -use ; -use ; - -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; -degrees = 2; - -row_spline = function(points) bspline_curve(t_step, degrees, points); -column_spline = function(points) bspline_curve(t_step, degrees, points); - -function_grapher(sf_splines(ctrl_pts, row_spline, column_spline), thickness); -*/ - -/* - -use ; -use ; -use ; - -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; - -row_spline = function(points) bezier_curve(t_step, points); -column_spline = function(points) bezier_curve(t_step, points); - -function_grapher(sf_splines(ctrl_pts, row_spline, column_spline), thickness); - -*/ - -/* - -use ; -use ; -use ; - -use ; - -ctrl_pts = [ - [[0, 0, 20], [20, 0, -15], [90, 0, 30], [200, 0, 5]], - [[0, 20, 30], [30, 30, -25], [80, 40, 20], [100, 50, 5]], - [[0, 100, 0], [20, 90, 15], [90, 100, 10], [100, 100, 45]], - [[0, 110, 0], [40, 120, -35], [90, 130, 20], [120, 120, 15]] -]; - -thickness = 2; -t_step = 0.05; - -row_spline = function(points) curve(t_step, points); -column_spline = function(points) curve(t_step, points); - -function_grapher(sf_splines(ctrl_pts, row_spline, column_spline), thickness); - -for(i = [0:3]) { - %hull_polyline3d(ctrl_pts[i]); - #hull_polyline3d(curve(t_step, ctrl_pts[i])); -} - -*/ \ No newline at end of file + ]; \ No newline at end of file