cap.hs

cap.stl

raw haskell source

#!/usr/bin/env stack
{- stack script --resolver lts-22.6 
    --package linear
    --package waterfall-cad
    --extra-dep waterfall-cad-0.3.0.0
    --extra-dep opencascade-hs-0.3.0.0
-}

{--
This is a Haskell Stack script, it's executable, and needs the Haskell Stack Build Tool installed to work.

http://docs.haskellstack.org/en/stable/

On Linux, you'll need to install opencascade before running this.
On Debian based systems, this can be done with the following command:

    sudo apt-get install libocct-data-exchange-7.6 libocct-data-exchange-dev libocct-draw-7.6 libocct-draw-dev libocct-foundation-7.6 libocct-foundation-dev libocct-modeling-algorithms-7.6 libocct-modeling-algorithms-dev libocct-modeling-data-7.6 libocct-modeling-data-dev libocct-ocaf-7.6 libocct-ocaf-dev libocct-visualization-7.6 libocct-visualization-dev occt-misc

On Macos, you should be able to install OpenCASCADE via homebrew:

    brew install opencascade

On Macos, you'll also need to configure the path to the OpenCASCADE header files, either via extra-include-dirs, or CPATH:

    export CPATH=$CPATH:/usr/local/Cellar/opencascade/7.*/include/opencascade/
--}

import qualified Waterfall 
import Linear 
import Data.Function ((&))

object :: Waterfall.Solid
object = 
    let cubeBelow = 
            Waterfall.centeredCube &
                Waterfall.translate (-0.5 *^ unit _z) &
                Waterfall.uScale 3 
        removeBottom = (`Waterfall.difference` cubeBelow)
        dome = removeBottom $ Waterfall.unitSphere
        brim = 
            Waterfall.prism 0.05 $ Waterfall.fromPath $ Waterfall.pathFrom (V2 0 1)
                [ Waterfall.lineTo (V2 1 1)
                , Waterfall.bezierTo (V2 1.6 1) (V2 1.75 0.4)(V2 1.75 0)
                , Waterfall.bezierTo (V2 1.75 (-0.4)) (V2 1.6 (-1)) (V2 1 (-1))
                , Waterfall.lineTo (V2 0 (-1))
                , Waterfall.lineTo (V2 0 1)
                ]
        headspace = Waterfall.uScale 0.95 Waterfall.unitSphere
        bandgap = 
            Waterfall.centeredCylinder &
                Waterfall.scale (V3 0.3 0.4 1) &
                Waterfall.rotate (unit _y) (pi/2) &
                removeBottom &
                Waterfall.translate (V3 (-1) 0 0.1)
        in  mconcat [dome, brim] `Waterfall.difference` mconcat [headspace, bandgap]

main :: IO ()
main = Waterfall.writeSTL 0.01 "cap.stl" object