title: Calculate Normals from Heightmap
body: <p>I am trying to convert an heightmap into a matrix of normals using central differencing which will later correspond to the steepness of a giving point.</p>
  
  <p>I found several links with correct results but without explaining the math behind.</p>
  
  <pre><code>  T
  L O R
    B
  </code></pre>
  
  <p>From <a href="https://www.leadwerks.com/community/topic/16244-calculate-normals-from-heightmap/" rel="noreferrer">this link</a> I realised I can just do:</p>
  
  <pre><code>Vec3 normal = Vec3(2*(R-L), 2*(B-T), -4).Normalize();
  </code></pre>
  
  <p>The thing is that I don't know where the <code>2*</code> and <code>-4</code> comes from.</p>
  
  <p>In <a href="https://math.stackexchange.com/questions/2326181/when-to-use-forward-or-central-difference-approximations">this explanation of central differencing</a> I see that we should divide that value by 2, but I still don't know how to connect all of this.</p>
  
  <p>What I really want to know is the linear algebra definition behind this.
  I have an heightmap, I want to measure the central differences and I want to obtain the normal vector to use later to measure the steepness.</p>
  
  <p>PS: the Z-axis is the height.</p>