# r2stl.r - produce an STL file containing a 3D surface plot
# suitable for printing using a 3D printer or rapid prototyper
# Version 0.1, 2012 by Ian Walker, University of Bath, i.walker@bath.ac.uk
# Released under a Creative Commons BY-NC-SA licence
# The data take the same form as in R's persp() plots: x and y
# represent a grid and z gives heights above this grid
r2stl = 1, we interpret this not as the minimum
# proportion of the object to be printed, but as the height
# of the printed object in mm, and provide a 0.5 mm minimum
# (0.5 mm seems a common minimum recommended height for many 3D printers)
if (min.height >= 1) {
min.height 1 | min(zz) < 0) zz