diff options
author | Steven <steven.vasilogianis@gmail.com> | 2019-03-26 19:12:46 -0400 |
---|---|---|
committer | Steven <steven.vasilogianis@gmail.com> | 2019-03-26 19:12:46 -0400 |
commit | 55ec091d02ae2c4d46ae055a05183218780aac34 (patch) | |
tree | ae52261b0d9da0c1d5d1d5ce796740a9b63f1ec7 | |
parent | c8ecdd4b892e819555bcd6a7cef76197dd864f2c (diff) |
Carpentry helper model for Graphics.OpenSCAD (rough draft for review)
-rw-r--r-- | OpenSCAD/Carpentry.hs | 53 |
1 files changed, 53 insertions, 0 deletions
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 @@ | |||
1 | module OpenSCAD.Carpentry | ||
2 | ( placeL | ||
3 | , placeL' | ||
4 | ) where | ||
5 | |||
6 | import Graphics.OpenSCAD | ||
7 | import Linear.V3 | ||
8 | import Control.Lens | ||
9 | |||
10 | placeL :: | ||
11 | (Double, Double, Double) | ||
12 | -> Char | ||
13 | -> [Double] | ||
14 | -> Double | ||
15 | -> Double | ||
16 | -> [Model3d] | ||
17 | placeL (x, y, z) axis w v u = placeL' x y z axis w v u | ||
18 | |||
19 | placeL' :: | ||
20 | Double | ||
21 | -> Double | ||
22 | -> Double | ||
23 | -> Char | ||
24 | -> [Double] | ||
25 | -> Double | ||
26 | -> Double | ||
27 | -> [Model3d] | ||
28 | placeL' bx by bz axis w v u | ||
29 | | axis == 'x' = place [(t, v, u) | t <- w] | ||
30 | | axis == 'y' = place [(v, t, u) | t <- w] | ||
31 | | axis == 'z' = place [(v, u, t) | t <- w] | ||
32 | where | ||
33 | place coords = map (\y -> translate y $ box bx by bz) coords | ||
34 | |||
35 | |||
36 | -- These are some helper functions for modeling carpentry projects w/ Graphics.OpenSCAD | ||
37 | -- If we want to model a deck, the railings will be placed along an x axis: | ||
38 | -- railingBoard = (2, 2, 48) -- 2 by 2 by 42 | ||
39 | -- railingPositions = [(w,0,4) | w <- [0,6..12*10]] -- one rail board every 6 inches for 10 feet | ||
40 | -- floorBoard = (2,4,12*10) | ||
41 | -- floorBoardPositions = [(0,w,0) | w <- [0,4..12*10]] | ||
42 | |||
43 | -- so the pattern is that in carpentry projects you generally have various sized | ||
44 | -- boards which get placed along some axis. placeL is a my attempt to | ||
45 | -- generalizing this pattern: | ||
46 | -- placeL railingBoard 'x' [0,4..12*10] 0 6 | ||
47 | -- placeL floorBoard 'y' [0,4..] 0 0 | ||
48 | -- | ||
49 | -- It works as intended, but admittedly does not "feel" like a proper haskell | ||
50 | -- solution. I would appreciate any advice towards a more "proper" solution. | ||
51 | -- As well, I get the following compiler warning which I am not sure | ||
52 | -- | ||
53 | |||