Produce G-Code for a Height Field

In this tutorial we will produce machine code for milling a height field surface using parallel style machining. A height-field is a special kind of surface where all points are on a regular xy-grid and only the z-coordinate is varying. Machining such surfaces is rather simple and instructive.



  1. You have studies the profiling code tutorial and understand that all machine paths are just polylines defining the sequence of tool center point locations.
  2. You have recreated the above pictured set of input parameters and output panels.
  3. We are working in a Rhino document with millimeters as units (all units are metric) and the top of material working plane coincides with the document’s World XY plane.



  1. Compute the grid dimensions by dividing the total part width and length (eg. 300 x 400mm) with the resolution factor (eg. 5mm).
  2. Scan the grid with two nested loops construct and produce a series of polylines also known as scan lines (this is how old monitors used to beam images on screen).
  3. Flip every other scan line using mod 2 arithmetic such that when we join scan lines into the master machine path polyline the points will appear in a zig-zag pattern.
  4. Apply a signal map from grid coordinates to physical coordinates, linear in XY and in addition perform as few non-linear transforms for computing the z-coordinate such that it appears on a undulating surface.
  5. When playing with transcendental functions (sine/cosine) it is useful to define the complete form including the phase, period and amplitude for better control the end design.
  6. After the path is generated, translate it below the top of material plane and add a lower bound slab for visual inspection of potentially machining clashes between tool and the router’s bed plate.
  7. Reuse the points generated during the path and code generations for constructing a proper nurbs surface from a point grid for end product visual evaluation.
  8. Finally, given a specific feed rate (machining speed in mm/min) and total machine path length (mm) approximately compute the machine production time!



  1. The style of the procedure presented here is highly advisable. It is cleaner and better to separate the surface generation logic from the machine code production. It is even better to place high-level logic in separate function such that code is its own documentation (instead of adding all the information above).
  2. Using a list of strings seems to work better with Grasshopper with very large bodies of text. You can copy/paste the data into notepad and save the machine file as previously. A new line (\r\n) will be automatically appended for each line of text.
  3. It is very easy to go overboard using very fine resolution (eg. 0.1mm) producing fifilions of points and instructions. The machine may not be able to handle very large files. In that case you will have to split the machine code into multiple files.
  4. The resolution factor, delta, is also our machining step-over parameter. For a 6mm ball mill tool we have 0.5mm overlap laterally among consecutive parallel cuts. The scallop artifact will thus be real and perhaps beautiful.
  5. Question: Does this approach to machining a height field surface makes sense? Even if we reduce the step over (increase grid resolution) to sub-millimeter level. Or is there something inherently wrong about it geometrically?
  6. Even 10mm of cutting depth is sufficient to produce very powerful and evocative objects. It is the way the light and shadow that exaggerates the glyph.
  7. Typical construction grade blue/pink XPS foam (30Kg/m3) tears with speeds higher than 1,500mm/min and lower than 10,000 RPMs. The first sample was cut at 3,000mm/min while the second at 1,500mm/min.
  8. Note that the deep points of the surface show more tearing, which implies that material was not escaping up the flute fast enough. Perhaps the carbide tool was not cut for the job or we should have carved the surface in multiple depth passes.