diff --git a/geometry.scad b/geometry.scad index c70272f..8bddec9 100644 --- a/geometry.scad +++ b/geometry.scad @@ -1278,5 +1278,111 @@ module region(r) } +// Module: heightfield() +// Usage: +// heightfield(heightfield, [size], [bottom]); +// Description: +// Given a regular rectangular 2D grid of scalar values, generates a 3D surface where the height at +// any given point is the scalar value for that position. +// Arguments: +// heightfield = The 2D rectangular array of heights. +// size = The [X,Y] size of the surface to create. If given as a scalar, use it for both X and Y sizes. +// bottom = The Z coordinate for the bottom of the heightfield object to create. Must be less than the minimum heightfield value. Default: 0 +// Example: +// heightfield(size=[100,100], bottom=-20, heightfield=[ +// for (x=[-180:4:180]) [for(y=[-180:4:180]) 10*cos(3*norm([x,y]))] +// ]); +// Example: +// intersection() { +// heightfield(size=[100,100], heightfield=[ +// for (x=[-180:5:180]) [for(y=[-180:5:180]) 10+5*cos(3*x)*sin(3*y)] +// ]); +// cylinder(h=50,d=100); +// } +module heightfield(heightfield, size=[100,100], bottom=0, convexity=10) +{ + size = is_num(size)? [size,size] : point2d(size); + dim = array_dim(heightfield); + assert(dim.x!=undef); + assert(dim.y!=undef); + assert(bottom