From 55ec091d02ae2c4d46ae055a05183218780aac34 Mon Sep 17 00:00:00 2001 From: Steven Date: Tue, 26 Mar 2019 19:12:46 -0400 Subject: Carpentry helper model for Graphics.OpenSCAD (rough draft for review) --- OpenSCAD/Carpentry.hs | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 OpenSCAD/Carpentry.hs diff --git a/OpenSCAD/Carpentry.hs b/OpenSCAD/Carpentry.hs new file mode 100644 index 0000000..995d785 --- /dev/null +++ b/OpenSCAD/Carpentry.hs @@ -0,0 +1,53 @@ +module OpenSCAD.Carpentry +( placeL +, placeL' + ) where + +import Graphics.OpenSCAD +import Linear.V3 +import Control.Lens + +placeL :: + (Double, Double, Double) + -> Char + -> [Double] + -> Double + -> Double + -> [Model3d] +placeL (x, y, z) axis w v u = placeL' x y z axis w v u + +placeL' :: + Double + -> Double + -> Double + -> Char + -> [Double] + -> Double + -> Double + -> [Model3d] +placeL' bx by bz axis w v u + | axis == 'x' = place [(t, v, u) | t <- w] + | axis == 'y' = place [(v, t, u) | t <- w] + | axis == 'z' = place [(v, u, t) | t <- w] + where + place coords = map (\y -> translate y $ box bx by bz) coords + + +-- These are some helper functions for modeling carpentry projects w/ Graphics.OpenSCAD +-- If we want to model a deck, the railings will be placed along an x axis: +-- railingBoard = (2, 2, 48) -- 2 by 2 by 42 +-- railingPositions = [(w,0,4) | w <- [0,6..12*10]] -- one rail board every 6 inches for 10 feet +-- floorBoard = (2,4,12*10) +-- floorBoardPositions = [(0,w,0) | w <- [0,4..12*10]] + +-- so the pattern is that in carpentry projects you generally have various sized +-- boards which get placed along some axis. placeL is a my attempt to +-- generalizing this pattern: +-- placeL railingBoard 'x' [0,4..12*10] 0 6 +-- placeL floorBoard 'y' [0,4..] 0 0 +-- +-- It works as intended, but admittedly does not "feel" like a proper haskell +-- solution. I would appreciate any advice towards a more "proper" solution. +-- As well, I get the following compiler warning which I am not sure +-- + -- cgit v1.2.3