title: How to calculate the slope of a point on a terrain data (e.g. Digital Elevation Matrix)
body: <p>I want to implement a 3D car racing game and I need to approximate the magnitude and the direction of the slope of any arbitrary point on a terrain.</p>
  
  <p>Terrain Data Format:<br>
  - heights[ ][ ]: 2D array of floats (representing heights in meters)<br>
  - unit: horizontal unit distance between (i, j) - (i, j+1) and between (i, j) - (i+1, j) in meters</p>
  
  <p>Ex:  </p>
  
  <pre><code>3|1311
  2|2542 &lt;-- 2D array of heights in meters
  1|2231   (unit distance between two cell is, say, 1 meters)
  0|1121   (so the highest point of the terrain (x = 1.5 meters, y = 2.5 meters)
    ----      is 5 meters high)
    0123
  </code></pre>
  
  <p>What is the value and direction of the slope at point, say, (x = 1.75 meters, y = 2.25 meters)?</p>
  
  <p>What would your interpolation algorithm be?</p>