From 3be3a271e6b317a1aa9f3e0201c324f8f2f17297 Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Fri, 14 Jun 2019 13:44:47 +0800 Subject: [PATCH] c-style for loop --- src/torus_knot.scad | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/torus_knot.scad b/src/torus_knot.scad index 9d91ec1a..607f22c0 100644 --- a/src/torus_knot.scad +++ b/src/torus_knot.scad @@ -8,14 +8,16 @@ * **/ -function torus_knot(p, q, phi_step) = [ - for(phi = [0:phi_step:PI * 2]) - let( - degree = phi * 180 / PI, - r = cos(q * degree) + 2, - x = r * cos(p * degree), - y = r * sin(p * degree), - z = -sin(q * degree) - ) - [x, y, z] -]; \ No newline at end of file +function torus_knot(p, q, phi_step) = + let(tau = PI * 2) + [ + for(phi = 0; phi < tau; phi = phi + phi_step) + let( + degree = phi * 180 / PI, + r = cos(q * degree) + 2, + x = r * cos(p * degree), + y = r * sin(p * degree), + z = -sin(q * degree) + ) + [x, y, z] + ]; \ No newline at end of file