Skip to content

Instantly share code, notes, and snippets.

@aavogt
Created May 28, 2025 02:26
Show Gist options
  • Save aavogt/1ca7c5a2d8590682c3c985fac16d7450 to your computer and use it in GitHub Desktop.
Save aavogt/1ca7c5a2d8590682c3c985fac16d7450 to your computer and use it in GitHub Desktop.
a grid of ellipsoidal bumps on a rectangular baseplate
{-# HLINT ignore "Eta reduce" #-}
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE RecordWildCards #-}
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
import Control.Lens
import Linear
import Waterfall
import Waterfall.IO
fi x = fromIntegral x
data Dimpler = Dimpler
{ h, m :: Double, -- baseplate height and margin
ellipseParams :: V3 Double,
nx, ny :: Int, -- number of ellipses
dx, dy :: Double -- ellipse spacing
}
dimpler0 = Dimpler 2 4 (V3 5 4 3) 3 8 12 15
marginBox Dimpler {..} x = maybe mempty (aabbToSolid . hm) $ axisAlignedBoundingBox x
where
hm corners =
corners
& _1 . _xy -~ V2 m m
& _2 . _xy +~ V2 m m
& _2 . _z .~ (corners ^. _1 . _z + corners ^. _2 . _z) / 2
& setH
setH cs = cs & _1 . _z .~ (cs ^. _2 . _z - h)
bottomHalfBox x = maybe mempty (aabbToSolid . halveZ) $ axisAlignedBoundingBox x
where
halveZ (a@(V3 _ _ az), V3 bx by bz) = (a, V3 bx by ((az + bz) / 2))
renderDimpler :: Dimpler -> Solid
renderDimpler dimpler@Dimpler {..} = marginBox dimpler ellipses <> (ellipses ~-~ bb)
where
wx = fi (nx - 1) * dx + 2 * m
wy = fi (ny - 1) * dy + 2 * m
ellipse1 i j = translate (V3 (m + fi i * dx) (m + fi j * dy) h) $ scale ellipseParams unitSphere
ellipses = foldl1 union [ellipse1 i j | i <- [0 .. nx - 1], j <- [0 .. ny - 1]]
bb = bottomHalfBox ellipses
main = writeSTEP "1.step" (renderDimpler dimpler0)
executable:
main:
main.hs
dependencies:
- base
- waterfall-cad
- linear
- lens
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment