From 933b2d9d73ce1008a727065676d5cfc0612231ca Mon Sep 17 00:00:00 2001 From: zhao Date: Thu, 12 Jan 2023 00:28:36 -0500 Subject: [PATCH] add halfspace --- helper/common.scad | 2 +- helper/halfspace.scad | 16 ++++++++++++++-- helper/math.scad | 9 +++++++++ helper/rotation.scad | 3 --- 4 files changed, 24 insertions(+), 6 deletions(-) delete mode 100644 helper/rotation.scad diff --git a/helper/common.scad b/helper/common.scad index dc0c2d7..2fb5f4e 100644 --- a/helper/common.scad +++ b/helper/common.scad @@ -3,7 +3,7 @@ */ $fn=64; - +// TODO move these to math eps=0.0001; inf10 = 10; diff --git a/helper/halfspace.scad b/helper/halfspace.scad index 4553fe5..503a0a1 100644 --- a/helper/halfspace.scad +++ b/helper/halfspace.scad @@ -1,2 +1,14 @@ -// TODO -// probably want to get rotations first \ No newline at end of file + +// Wake up sheeple. Halfspaces are just really BIG cubes! +include <./math.scad> +include <./common.scad> + +module halfspace(vpos, p) { + translate(p) + align(a=[0,0,1], b=vpos) + translate(v=[0,0,-inf/2]) + cube(size=[inf, inf, inf], center=true); +} + + +halfspace(vpos=[1,1,1], p=[10,10,10]); \ No newline at end of file diff --git a/helper/math.scad b/helper/math.scad index 9c13773..da7373d 100644 --- a/helper/math.scad +++ b/helper/math.scad @@ -10,3 +10,12 @@ function mirror4XY(midpoint, offsetX, offsetY) = [midpoint[0]-offsetX, midpoint[1]+offsetY, midpoint[2]], [midpoint[0]-offsetX, midpoint[1]-offsetY, midpoint[2]], [midpoint[0]+offsetX, midpoint[1]-offsetY, midpoint[2]]]; + + +module align(a,b) { + rot_axis = cross(a,b); + angle = acos(a*b/ (norm(a)*norm(b))); + + rotate(v=rot_axis, a=angle) + children(0); +} diff --git a/helper/rotation.scad b/helper/rotation.scad deleted file mode 100644 index 91a6e70..0000000 --- a/helper/rotation.scad +++ /dev/null @@ -1,3 +0,0 @@ -// TODO - -// eg transformation to rotate vector a to vector b, etc \ No newline at end of file