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
|
{-# LANGUAGE RecordWildCards #-}
import Control.Lens
import Graphics.OpenSCAD
import Linear.V3
genscad :: [(V3 Double, V3 Double)] -> String
genscad = render . transBoxes
transBoxes :: [(V3 Double, V3 Double)] -> Model Vector3d
transBoxes = union . map transBox
transBox :: (V3 Double, V3 Double) -> Model3d
transBox (V3 x1 y1 z1, V3 x2 y2 z2) = translate (x1,y1,z1) $ box x2 y2 z2
type Inches = Double
data Shelf = Shelf {
shelfThickness :: Inches,
shelfWidth :: Inches,
shelfLength :: Inches,
shelfHeights :: [Inches],
shelfSideDimX :: Inches
}
shelves' :: Shelf -> [(V3 Double, V3 Double)]
shelves' Shelf{..} = [(p, V3 shelfLength shelfWidth shelfThickness) | p <- shelvesPos]
where
shelfHeight = sum shelfHeights + (shelfThickness * (fromIntegral (length shelfHeights) + 1))
shelfSideDim :: V3 Inches
shelfSideDim = V3 shelfSideDimX shelfWidth shelfHeight
shelfYPos :: [Inches]
shelfYPos = scanl (+) 0 [h+shelfThickness| h <- shelfHeights]
shelvesPos :: [V3 Double]
shelvesPos = [V3 (shelfSideDim ^. _x) 0 y | y <- shelfYPos]
myShelf :: Shelf
myShelf = Shelf {
shelfThickness = 0.5,
shelfWidth = 8,
shelfLength = 36 * 2,
shelfHeights = [12, 10, 8, 8, 8, 8, 8],
shelfSideDimX = 0.5
}
modelShelf :: Shelf -> Model3d
modelShelf = transBoxes . shelves'
main :: IO ()
main = draw $ modelShelf myShelf
|