Commit fb38f9 added torus

3 files Authored and Committed by Tom Hawkins 7 years ago
added torus

    
 1 @@ -65,22 +65,22 @@
 2       Union        a b   -> printf "union()        {\n%s%s}\n" (indent $ solid a) (indent $ solid b)
 3       Intersection a b   -> printf "intersection() {\n%s%s}\n" (indent $ solid a) (indent $ solid b)
 4       Difference   a b   -> printf "difference()   {\n%s%s}\n" (indent $ solid a) (indent $ solid b)
 5 -     Primitive t (r, g, b, o) p -> printf "color([%f, %f, %f, %f]) {\n%s}\n" r g b o $ indent $ transform $ reverse t
 6 +     Primitive t (r, g, b, o) p -> printf "color([%f, %f, %f, %f]) %s\n" r g b o $ transform $ reverse t
 7         where
 8         transform :: [Transform] -> String
 9         transform a = case a of
10           [] -> primitive p
11 -         Scale (x, y, z) : rest -> printf "scale ([%f, %f, %f])     {\n%s}\n" x y z          $ indent $ transform rest
12 -         Move  (x, y, z) : rest -> printf "translate ([%f, %f, %f]) {\n%s}\n" x y z          $ indent $ transform rest
13 -         RotateX a       : rest -> printf "rotate (%f, [1, 0, 0])   {\n%s}\n" (a * 180 / pi) $ indent $ transform rest
14 -         RotateY a       : rest -> printf "rotate (%f, [0, 1, 0])   {\n%s}\n" (a * 180 / pi) $ indent $ transform rest
15 -         RotateZ a       : rest -> printf "rotate (%f, [0, 0, 1])   {\n%s}\n" (a * 180 / pi) $ indent $ transform rest
16 +         Scale (x, y, z) : rest -> printf "scale ([%f, %f, %f]) %s"     x y z          $ transform rest
17 +         Move  (x, y, z) : rest -> printf "translate ([%f, %f, %f]) %s" x y z          $ transform rest
18 +         RotateX a       : rest -> printf "rotate (%f, [1, 0, 0]) %s"   (a * 180 / pi) $ transform rest
19 +         RotateY a       : rest -> printf "rotate (%f, [0, 1, 0]) %s"   (a * 180 / pi) $ transform rest
20 +         RotateZ a       : rest -> printf "rotate (%f, [0, 0, 1]) %s"   (a * 180 / pi) $ transform rest
21   
22         primitive :: Primitive -> String
23         primitive a = case a of
24           Sphere d     -> printf "sphere(r = %f, $fn = 100);\n" (d / 2)
25           Cone bd td h -> printf "cylinder(h = %f, r1 = %f, r2 = %f, center = false, $fn = 100);\n" h (td / 2) (bd / 2)
26 -         Box (x1, x2) (y1, y2) (z1, z2) -> printf "translate ([%f, %f, %f]) {\n\tcube(size = [%f, %f, %f], center = false);\n}\n" xmin ymin zmin (xmax - xmin) (ymax - ymin) (zmax - zmin)
27 +         Box (x1, x2) (y1, y2) (z1, z2) -> printf "translate ([%f, %f, %f]) cube(size = [%f, %f, %f], center = false);\n" xmin ymin zmin (xmax - xmin) (ymax - ymin) (zmax - zmin)
28             where
29             xmin = min x1 x2
30             xmax = max x1 x2
 1 @@ -7,6 +7,7 @@
 2     , box
 3     , cube
 4     , cylinder
 5 +   , cylinder'
 6     , tube
 7     , radial
 8     , torus
 9 @@ -86,6 +87,10 @@
10   cylinder :: Double -> Double -> Solid
11   cylinder d h = cone d d h
12   
13 + -- | Same as cylinder, but centered at the origin.
14 + cylinder' :: Double -> Double -> Solid
15 + cylinder' d h = moveZ (- h / 2) $ cylinder d h
16 + 
17   -- | A hollow cylinder with base at the origin, given outer diameter, inner diamter, and height.
18   tube od id h = difference (cylinder od h) (moveZ (-h) $ cylinder id (4 * h))
19   
1 @@ -10,7 +10,7 @@
2   
3   # Release Notes
4   
5 - 0.1.1    ???
6 + 0.1.1    06/11/11
7   
8   - Added torus primitive.
9