diff options
-rw-r--r-- | shelves.hs | 113 |
1 files changed, 38 insertions, 75 deletions
@@ -1,93 +1,56 @@ | |||
1 | {-# LANGUAGE RecordWildCards #-} | ||
1 | import Control.Lens | 2 | import Control.Lens |
2 | import Graphics.OpenSCAD | 3 | import Graphics.OpenSCAD |
3 | import Linear.V3 | 4 | import Linear.V3 |
4 | 5 | ||
5 | genscad :: [(V3 Double, V3 Double)] -> String | 6 | genscad :: [(V3 Double, V3 Double)] -> String |
6 | genscad = render . union . map transBox | 7 | genscad = render . transBoxes |
7 | where | ||
8 | transBox :: (V3 Double, V3 Double) -> Model3d | ||
9 | transBox (V3 x1 y1 z1, V3 x2 y2 z2) = translate (x1,y1,z1) $ box x2 y2 z2 | ||
10 | |||
11 | data Shelf | ||
12 | |||
13 | myShelf :: Shelf | ||
14 | myShelf = undefined | ||
15 | |||
16 | modelShelf :: Shelf -> Model3d | ||
17 | modelShelf = undefined | ||
18 | |||
19 | main :: IO () | ||
20 | main = draw $ modelShelf myShelf | ||
21 | |||
22 | shelf_thickness :: Double | ||
23 | shelf_thickness = 0.5 | ||
24 | shelf_width :: Double | ||
25 | shelf_width = 8 | ||
26 | shelf_length :: Double | ||
27 | shelf_length = 36 * 2 | ||
28 | shelf_dim :: V3 Double | ||
29 | shelf_dim = V3 shelf_length shelf_width shelf_thickness | ||
30 | |||
31 | shelf_heights :: [Double] | ||
32 | shelf_heights = [12, 10, 8, 8, 8, 8, 8] | ||
33 | |||
34 | -- working algorithm doing the same as `scanl (+) 0 shelf_heights` | ||
35 | --acc [] = [0] | ||
36 | --acc xs = acc(init xs) ++ [sum xs] | ||
37 | |||
38 | shelf_height :: Double | ||
39 | shelf_height = (sum shelf_heights) + (shelf_dim ^. _z * (fromIntegral (length shelf_heights) + 1)) | ||
40 | 8 | ||
41 | side_dim :: V3 Double | 9 | transBoxes :: [(V3 Double, V3 Double)] -> Model Vector3d |
42 | side_dim = V3 0.5 shelf_width shelf_height | 10 | transBoxes = union . map transBox |
43 | 11 | ||
44 | --shelf_y_poss = scanl (+) 0 shelf_heights | 12 | transBox :: (V3 Double, V3 Double) -> Model3d |
45 | shelf_y_poss :: [Double] | 13 | transBox (V3 x1 y1 z1, V3 x2 y2 z2) = translate (x1,y1,z1) $ box x2 y2 z2 |
46 | shelf_y_poss = scanl (+) 0 [h+shelf_thickness| h <- shelf_heights] | ||
47 | shelves_pos :: [V3 Double] | ||
48 | shelves_pos = [V3 (side_dim ^. _x) 0 y | y <- shelf_y_poss] | ||
49 | shelves :: [(V3 Double, V3 Double)] | ||
50 | shelves = [(p, shelf_dim) | p <- shelves_pos] | ||
51 | 14 | ||
52 | --sides = [(V3 0 0 0, side_dim), (V3 (side_dim ^. _x + shelf_length) 0 0, side_dim)] | 15 | type Inches = Double |
53 | sides_pos :: [V3 Double] | ||
54 | sides_pos = [V3 0 0 0, V3 (side_dim ^. _x + shelf_length) 0 0] | ||
55 | sides :: [(V3 Double, V3 Double)] | ||
56 | sides = [(p, side_dim) | p <- sides_pos] | ||
57 | 16 | ||
58 | --V3_to_string v = drop 3 (show v) | 17 | data Shelf = Shelf { |
18 | shelfThickness :: Inches, | ||
19 | shelfWidth :: Inches, | ||
20 | shelfLength :: Inches, | ||
21 | shelfHeights :: [Inches], | ||
22 | shelfSideDimX :: Inches | ||
23 | } | ||
59 | 24 | ||
60 | --scad_place (p,d) = "translate([ " ++ _V32s(p) ++ " ]) { cube([ " ++ _V32s(d) ++ " ]);}" | 25 | shelfDim :: Shelf -> V3 Inches |
61 | --genscad objs = concat $ map (++ "\n") $ map scad_place objs | 26 | shelfDim Shelf{..} = V3 shelfLength shelfWidth shelfThickness |
62 | 27 | ||
63 | scadshelf :: String | 28 | shelves' :: Shelf -> [(V3 Double, V3 Double)] |
64 | scadshelf = genscad $ shelves ++ sides | 29 | shelves' s@Shelf{..} = [(p, shelfDim s) | p <- shelvesPos] |
65 | 30 | where | |
66 | --gen_shelf :: [Fractional] -> Fractional -> Fractional -> [Char] | 31 | shelfHeight = (sum shelfHeights) + (shelfDim s ^. _z * (fromIntegral (length shelfHeights) + 1)) |
67 | --gen_shelf shelf_heights depth length = | ||
68 | |||
69 | |||
70 | |||
71 | -- main :: IO () | ||
72 | -- main = do putStrLn scadshelf | ||
73 | |||
74 | |||
75 | |||
76 | --main = map (putStrLn) ["one", "two"] | ||
77 | |||
78 | --genshelf = genscad $ shelves ++ sides | ||
79 | 32 | ||
80 | --main = map print $ gen_scad $ shelves ++ sides | 33 | shelfSideDim :: V3 Inches |
34 | shelfSideDim = V3 shelfSideDimX shelfWidth shelfHeight | ||
81 | 35 | ||
82 | --scad_place_sides = map (scad_place_board) [[[V3 0 0 0], side_dim], [[V3 side_dim ^. _x, 0, 0], side_dim]] | 36 | shelfYPos :: [Inches] |
37 | shelfYPos = scanl (+) 0 [h+shelfThickness| h <- shelfHeights] | ||
83 | 38 | ||
84 | --scad_place_shelf vpos = scad_place_board show([0, vpos, 0]) show(shelfd) | 39 | shelvesPos :: [V3 Double] |
40 | shelvesPos = [V3 (shelfSideDim ^. _x) 0 y | y <- shelfYPos] | ||
85 | 41 | ||
42 | myShelf :: Shelf | ||
43 | myShelf = Shelf { | ||
44 | shelfThickness = 0.5, | ||
45 | shelfWidth = 8, | ||
46 | shelfLength = 36 * 2, | ||
47 | shelfHeights = [12, 10, 8, 8, 8, 8, 8], | ||
48 | shelfSideDimX = 0.5 | ||
49 | } | ||
86 | 50 | ||
87 | --genscad shelves ++ sides | 51 | modelShelf :: Shelf -> Model3d |
52 | modelShelf = transBoxes . shelves' | ||
88 | 53 | ||
89 | --gen_openscad = map (scad_place_piece | 54 | main :: IO () |
55 | main = draw $ modelShelf myShelf | ||
90 | 56 | ||
91 | --accu [x] = x | ||
92 | --accu xs = sum(xs) ++ accu(tail xs) | ||
93 | -- OUTPUT: [0,5,8,10] | ||