summaryrefslogtreecommitdiff
path: root/OpenSCAD/Carpentry.hs
blob: 995d7859dcbbb3479a9e618f7dd1763bb940b74c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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 
--