From 63aab8011673684088efa52fed888c792f4c83a5 Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Sun, 15 May 2022 10:11:16 +0800 Subject: [PATCH] re-org vars --- src/ptf/ptf_bend.scad | 3 +-- src/ptf/ptf_circle.scad | 6 +----- src/ptf/ptf_ring.scad | 7 ++----- src/ptf/ptf_sphere.scad | 14 ++++++-------- src/ptf/ptf_torus.scad | 11 +++++------ src/ptf/ptf_x_twist.scad | 3 +-- src/ptf/ptf_y_twist.scad | 3 +-- 7 files changed, 17 insertions(+), 30 deletions(-) diff --git a/src/ptf/ptf_bend.scad b/src/ptf/ptf_bend.scad index ad30fb63..14ce0beb 100644 --- a/src/ptf/ptf_bend.scad +++ b/src/ptf/ptf_bend.scad @@ -12,8 +12,7 @@ function ptf_bend(size, point, radius, angle) = let( // ignored: size.y, x = is_undef(point.z) ? 0 : point.z, - a_step = angle / size.x, - a = a_step * point.x, + a = angle / size.x * point.x, r = radius + x ) [r * cos(a), r * sin(a), point.y]; \ No newline at end of file diff --git a/src/ptf/ptf_circle.scad b/src/ptf/ptf_circle.scad index e1513bfc..135f84f9 100644 --- a/src/ptf/ptf_circle.scad +++ b/src/ptf/ptf_circle.scad @@ -11,8 +11,4 @@ function ptf_circle(size, point) = let(p = point - size / 2) p == [0, 0] ? p : - let( - n = max(abs(p.x), abs(p.y)), - r = n * 1.41421356237 - ) - [p.y, p.x] * (r / norm(p)); \ No newline at end of file + [p.y, p.x] * (max(abs(p.x), abs(p.y)) / norm(p) * 1.41421356237); \ No newline at end of file diff --git a/src/ptf/ptf_ring.scad b/src/ptf/ptf_ring.scad index 8e9880d0..b9852ea2 100644 --- a/src/ptf/ptf_ring.scad +++ b/src/ptf/ptf_ring.scad @@ -12,8 +12,5 @@ use ; use ; function ptf_ring(size, point, radius, angle = 360, twist = 0) = - let( - a_step = angle / size.y, - twisted = ptf_y_twist(size, point, twist) - ) - ptf_rotate([radius + twisted.x, 0, twisted.z], a_step * twisted.y); \ No newline at end of file + let(twisted = ptf_y_twist(size, point, twist)) + ptf_rotate([radius + twisted.x, 0, twisted.z], angle / size.y * twisted.y); \ No newline at end of file diff --git a/src/ptf/ptf_sphere.scad b/src/ptf/ptf_sphere.scad index ffb82f5b..f96fc81c 100644 --- a/src/ptf/ptf_sphere.scad +++ b/src/ptf/ptf_sphere.scad @@ -12,12 +12,10 @@ use ; function ptf_sphere(size, point, radius, angle = [180, 360]) = let( - z = is_undef(point.z) ? 0 : point.z, - za = angle[0], - xa = angle[1], - za_step = za / size.y, - rza = za_step * point.y, - rzpt = (radius + z) * [cos(rza), sin(rza), 0], - rxpt = ptf_rotate(rzpt, [90 - xa / size.x * point.x, 90, 0]) + z = is_undef(point.z) ? 0 : point.z, + rza = angle[0] / size.y * point.y ) - rxpt; \ No newline at end of file + ptf_rotate( + (radius + z) * [cos(rza), sin(rza), 0], + [90 - angle[1] / size.x * point.x, 90, 0] + ); \ No newline at end of file diff --git a/src/ptf/ptf_torus.scad b/src/ptf/ptf_torus.scad index d94f5a7a..1857446d 100644 --- a/src/ptf/ptf_torus.scad +++ b/src/ptf/ptf_torus.scad @@ -16,10 +16,9 @@ function ptf_torus(size, point, radius, angle = [360, 360], twist = 0) = r = radius[1] + (is_undef(point.z) ? 0 : point.z), A = angle[0], a = angle[1], - ya_step = a / size.x, - za_step = A / size.y, - twa_step = twist / size.y, - ya = 180 - point.x * ya_step + twa_step * point.y, - za = za_step * point.y + ya = 180 - point.x * a / size.x + twist / size.y * point.y ) - ptf_rotate([r * cos(ya) + R + r, 0, r * sin(ya)], za); \ No newline at end of file + ptf_rotate( + [r * cos(ya) + R + r, 0, r * sin(ya)], + A / size.y * point.y + ); \ No newline at end of file diff --git a/src/ptf/ptf_x_twist.scad b/src/ptf/ptf_x_twist.scad index 38f48b7b..9f670907 100644 --- a/src/ptf/ptf_x_twist.scad +++ b/src/ptf/ptf_x_twist.scad @@ -13,7 +13,6 @@ use ; function ptf_x_twist(size, point, angle) = let( y_offset = size.y / 2, - a_step = angle / size.x, y_centered = [point.x, point.y, is_undef(point.z) ? 0 : point.z] + [0, -y_offset, 0] ) - ptf_rotate(y_centered, [point.x * a_step, 0, 0]) + [0, y_offset, 0]; \ No newline at end of file + ptf_rotate(y_centered, [point.x * angle / size.x, 0, 0]) + [0, y_offset, 0]; \ No newline at end of file diff --git a/src/ptf/ptf_y_twist.scad b/src/ptf/ptf_y_twist.scad index ad291c00..d9def285 100644 --- a/src/ptf/ptf_y_twist.scad +++ b/src/ptf/ptf_y_twist.scad @@ -13,7 +13,6 @@ use ; function ptf_y_twist(size, point, angle) = let( x_offset = size.x / 2, - a_step = angle / size.y, x_centered = [point.x, point.y, is_undef(point.z) ? 0 : point.z] + [-x_offset, 0, 0] ) - ptf_rotate(x_centered, [0, point.y * a_step, 0]) + [x_offset, 0, 0]; \ No newline at end of file + ptf_rotate(x_centered, [0, point.y * angle / size.y, 0]) + [x_offset, 0, 0]; \ No newline at end of file