From 8bcdb263d3914838ca713c895d4838d931766a24 Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Sat, 7 May 2022 17:20:59 +0800 Subject: [PATCH] refactor --- src/_impl/_catmull_rom_spline.scad | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/_impl/_catmull_rom_spline.scad b/src/_impl/_catmull_rom_spline.scad index 9b11b154..eed77e05 100644 --- a/src/_impl/_catmull_rom_spline.scad +++ b/src/_impl/_catmull_rom_spline.scad @@ -2,11 +2,15 @@ use <../bezier_curve.scad>; function _catmull_rom_spline_4pts(t_step, points, tightness) = let( - p1x_0tightness = (points[2] - points[0]) / 4 + points[1], - v_p1x = points[1] - p1x_0tightness, - p1x = p1x_0tightness + v_p1x * tightness, - p2x_0tightness = (points[1] - points[3]) / 4 + points[2], - v_p2x = points[2] - p2x_0tightness, - p2x = p2x_0tightness + v_p2x * tightness + p1 = points[1], + p2 = points[2], + t = (tightness - 1) / 4 ) - bezier_curve(t_step, [points[1], p1x, p2x, points[2]]); + bezier_curve(t_step, + [ + p1, + (points[0] - p2) * t + p1, + (points[3] - p1) * t + p2, + p2 + ] + );