From 65789a6cb7128e96508fcd01a076d072984e0456 Mon Sep 17 00:00:00 2001 From: cactrot Date: Thu, 15 Dec 2022 14:33:35 -0500 Subject: [PATCH 1/3] Added mirror function based on elongate Couldn't figure out how to mirror an object with the existing operations. Tried negative scale factors and elongations without success. --- sdf/d3.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sdf/d3.py b/sdf/d3.py index f8c7aa0c..83342cee 100644 --- a/sdf/d3.py +++ b/sdf/d3.py @@ -403,6 +403,12 @@ def f(p): return other(_max(q, 0)) + w return f +@op3 +def mirror(other, offset): + def f(p): + return other(offset - p) + return f + @op3 def twist(other, k): def f(p): From d3092b8f15cb7ab787af48ed923bf39426441db4 Mon Sep 17 00:00:00 2001 From: cactrot Date: Thu, 15 Dec 2022 16:16:25 -0500 Subject: [PATCH 2/3] New version of mirror Rather than mirroring all axes at once this version should mirror about a plan in point and normal form. --- sdf/d3.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/sdf/d3.py b/sdf/d3.py index 83342cee..db6d827f 100644 --- a/sdf/d3.py +++ b/sdf/d3.py @@ -404,9 +404,16 @@ def f(p): return f @op3 -def mirror(other, offset): +def mirror(other, point=ORIGIN, normal=UP ): + x, y, z = _normalize(normal) + + matrix = np.array([ + [1-2*x*x, -2*x*y, -2*x*z], + [ -2*x*y, 1-2*y*y, -2*y*z], + [ -2*x*z, -2*y*z, 1-2*z*z], + ]).T def f(p): - return other(offset - p) + return other(np.dot(p-point, matrix) + point) return f @op3 From b8cff22cc4d041ec04a14cabdefcf84bb4d7e44e Mon Sep 17 00:00:00 2001 From: cactrot Date: Sat, 7 Jan 2023 15:20:01 -0500 Subject: [PATCH 3/3] Added taper function Couldn't figure out how to do a taper with existing functions. --- sdf/d3.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/sdf/d3.py b/sdf/d3.py index db6d827f..24a7bb75 100644 --- a/sdf/d3.py +++ b/sdf/d3.py @@ -416,6 +416,17 @@ def f(p): return other(np.dot(p-point, matrix) + point) return f +@op3 +def taper(other, factor, start, end, e=ease.linear): + def f(p): + for each in p: + scale = (each[2]-start)/(end-start) + s = e(np.clip(scale, 0, 1))*factor + 1 + each[0] /= s + each[1] /= s + return other(p) + return f + @op3 def twist(other, k): def f(p):