Skip to content

Instantly share code, notes, and snippets.

@joe-warren
Created January 30, 2024 03:09
Show Gist options
  • Select an option

  • Save joe-warren/2bb2090ee08ce77d3f5f99776b6a0cdc to your computer and use it in GitHub Desktop.

Select an option

Save joe-warren/2bb2090ee08ce77d3f5f99776b6a0cdc to your computer and use it in GitHub Desktop.
import qualified Waterfall
import qualified Waterfall.TwoD.Shape as Shape
import Waterfall.Internal.Solid (debug)
import Linear
import Control.Lens ((^.))
import Data.Monoid (Endo (..))
tSlotCrossSection :: Waterfall.Path2D
tSlotCrossSection =
let oneQuarter =
Waterfall.pathFrom (V2 4 0)
[ Waterfall.lineTo (V2 4 3)
, Waterfall.lineRelative (V2 3 3)
, Waterfall.lineRelative (V2 1 0)
, Waterfall.lineRelative (V2 0 (-3))
, Waterfall.lineRelative (V2 2 0)
, Waterfall.lineTo (V2 10 10)
, Waterfall.lineRelative (V2 (-7) 0)
, Waterfall.lineRelative (V2 0 (-2))
, Waterfall.lineRelative (V2 3 0)
, Waterfall.lineRelative (V2 0 (-1))
, Waterfall.lineRelative (V2 (-3) (-3))
, Waterfall.lineTo (V2 0 4)
]
in Waterfall.repeatLooping oneQuarter
tSlotCrossSectionWider :: Waterfall.Path2D
tSlotCrossSectionWider =
let oneQuarter =
Waterfall.pathFrom (V2 4.25 0)
[ Waterfall.lineTo (V2 4.25 3)
, Waterfall.lineTo (V2 7 5.75)
, Waterfall.lineTo (V2 7.75 5.75)
, Waterfall.lineTo (V2 7.75 2.75)
, Waterfall.lineTo (V2 10.25 2.75)
, Waterfall.lineTo (V2 10.25 10.25)
, Waterfall.lineTo (V2 2.75 10.25)
, Waterfall.lineTo (V2 2.75 7.75)
, Waterfall.lineTo (V2 5.75 7.75)
, Waterfall.lineTo (V2 5.75 7)
, Waterfall.lineTo (V2 3 4.25)
, Waterfall.lineTo (V2 0 4.25)
]
in Waterfall.repeatLooping oneQuarter
screwDistance = 100
recessPadding = 10 -- distance from screw to nearest edge of recess
tSlotPadding = 3
recessDepth = 6
moduleHeight = 20
screwPenetration = 2.5
tSlotThin :: Waterfall.Solid
tSlotThin = Waterfall.prism (moduleHeight * 2) $ Shape.fromPath tSlotCrossSection
tSlotOld :: Waterfall.Solid
tSlotOld = Waterfall.prism (moduleHeight * 2) $ Shape.fromPath tSlotCrossSectionWider
tSlot :: Waterfall.Solid
tSlot = Waterfall.offset 0.5 1e-6
(Waterfall.scale (V3 20 20 (moduleHeight *4)) Waterfall.centeredCube `Waterfall.difference`
(mconcat [Waterfall.rotate (unit _z) (p * pi/2) $ Waterfall.translate (10 * unit _y) $ Waterfall.scale (V3 6 12 (moduleHeight * 6)) Waterfall.centeredCube | p<- [0..3]]))
bevel = Waterfall.roundConditionalFillet (\(s, e) -> if s ^. _z == e ^._z then Nothing else Just 2)
topSection :: Waterfall.Solid
topSection =
let solids =
Waterfall.box (V3 (screwDistance + 2 * recessPadding) (recessDepth*2) moduleHeight)
<> (bevel $ Waterfall.translate (V3 (-tSlotPadding) recessDepth 0) $ Waterfall.box (V3 (screwDistance + 20 + tSlotPadding *2) (20 + 2*tSlotPadding) moduleHeight))
-- M4, with a 8mm diameter head
screwHole = Waterfall.rotate (unit _x) (-pi/2) $
((Waterfall.translate (-50 * unit _z) $ Waterfall.scale (V3 2 2 100) Waterfall.unitCylinder)
<> Waterfall.scale (V3 4.25 4.25 100) Waterfall.unitCylinder )
tSlotHoles = appEndo $ foldMap Endo [ (`Waterfall.difference` (Waterfall.translate (V3 x (recessDepth + 10 + tSlotPadding) 0) tSlot)) | x <- [10, screwDistance + 10]]
screwHoles = appEndo $ foldMap Endo [ (`Waterfall.difference` (Waterfall.translate (V3 x screwPenetration (moduleHeight/2)) screwHole)) | x <- [10, screwDistance + 10]]
gap = Waterfall.translate (V3 (10+ screwDistance/2) 0 (-1)) $
Waterfall.scale (V3 30 20 (moduleHeight*2) ) Waterfall.unitCylinder
in (screwHoles (tSlotHoles solids)) `Waterfall.difference` gap
bottomSection :: Waterfall.Solid
bottomSection =
let solids =
Waterfall.box (V3 (screwDistance + 2 * recessPadding) (recessDepth*2) moduleHeight)
<> (bevel $ Waterfall.translate (V3 (-tSlotPadding) recessDepth 0) $ Waterfall.box (V3 (screwDistance + 20 + tSlotPadding *2) (20 + 2*tSlotPadding) moduleHeight))
-- M4, with a 8mm diameter head
screwHole = Waterfall.rotate (unit _x) (-pi/2) $
((Waterfall.translate (-50 * unit _z) $ Waterfall.scale (V3 2 2 100) Waterfall.unitCylinder)
<> Waterfall.scale (V3 4.25 4.25 100) Waterfall.unitCylinder )
tSlotHoles = appEndo $ foldMap Endo [ (`Waterfall.difference` (Waterfall.translate (V3 x (recessDepth + 10 + tSlotPadding) (-2)) tSlot)) | x <- [10, screwDistance + 10]]
screwHoles = appEndo $ foldMap Endo [ (`Waterfall.difference` (Waterfall.translate (V3 x screwPenetration (moduleHeight/2)) screwHole)) | x <- [10, screwDistance + 10]]
in (screwHoles . tSlotHoles $ solids) `Waterfall.union` (Waterfall.scale (V3 1 1 0.25) solids)
object :: Waterfall.Solid
object = Waterfall.prism 20 $ Shape.fromPath tSlotCrossSection
main :: IO ()
main = do
Waterfall.writeSTL 0.1 "monitor_thing_tslotThin.stl" tSlotThin
Waterfall.writeSTL 0.1 "monitor_thing_tslotOld.stl" tSlotOld
Waterfall.writeSTL 0.1 "monitor_thing_tslot.stl" tSlot
Waterfall.writeSTL 0.1 "monitor_thing_top.stl" topSection
Waterfall.writeSTL 0.1 "monitor_thing_bottom.stl" bottomSection
Waterfall.writeSTEP "monitor_thing_top.step" topSection
Waterfall.writeSTEP "monitor_thing_bottom.step" bottomSection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment