diff --git a/src/_impl/_shape_superformula_impl.scad b/src/_impl/_shape_superformula_impl.scad new file mode 100644 index 00000000..c0356551 --- /dev/null +++ b/src/_impl/_shape_superformula_impl.scad @@ -0,0 +1,20 @@ +use <__comm__/__ra_to_xy.scad>; +use <__comm__/__to_degree.scad>; + +function _superformula_r(angle, m1, m2, n1, n2 = 1, n3 = 1, a = 1, b = 1) = + pow( + pow(abs(cos(m1 * angle / 4) / a), n2) + + pow(abs(sin(m2 * angle / 4) / b), n3), + - 1 / n1 + ); + +function _shape_superformula_impl(phi_step, m1, m2, n1, n2 = 1, n3 = 1, a = 1, b = 1) = + let(tau = PI * 2) + [ + for(phi = 0; phi <= tau; phi = phi + phi_step) + let( + angle = __to_degree(phi), + r = _superformula_r(angle, m1, m2, n1, n2, n3, a, b) + ) + __ra_to_xy(r, angle) + ]; \ No newline at end of file diff --git a/src/shape_superformula.scad b/src/shape_superformula.scad index 1211416c..4468aaf7 100644 --- a/src/shape_superformula.scad +++ b/src/shape_superformula.scad @@ -8,23 +8,7 @@ * **/ -include <__comm__/__ra_to_xy.scad>; -include <__comm__/__to_degree.scad>; - -function _superformula_r(angle, m1, m2, n1, n2 = 1, n3 = 1, a = 1, b = 1) = - pow( - pow(abs(cos(m1 * angle / 4) / a), n2) + - pow(abs(sin(m2 * angle / 4) / b), n3), - - 1 / n1 - ); +use <_impl/_shape_superformula_impl.scad>; function shape_superformula(phi_step, m1, m2, n1, n2 = 1, n3 = 1, a = 1, b = 1) = - let(tau = PI * 2) - [ - for(phi = 0; phi <= tau; phi = phi + phi_step) - let( - angle = __to_degree(phi), - r = _superformula_r(angle, m1, m2, n1, n2, n3, a, b) - ) - __ra_to_xy(r, angle) - ]; \ No newline at end of file + _shape_superformula_impl(phi_step, m1, m2, n1, n2, n3, a, b); \ No newline at end of file diff --git a/test/test_shape_superformula.scad b/test/test_shape_superformula.scad index fe273b2c..b5a581de 100644 --- a/test/test_shape_superformula.scad +++ b/test/test_shape_superformula.scad @@ -1,5 +1,5 @@ -include ; -include ; +use ; +use ; module test_shape_superformula() { echo("==== test_shape_superformula ====");