title: Measure distance between lat/lon coordinates and utm coordinates
body: <p>I have a set of lat/lon coordinates for different nodes.<br>
  Since I have to represent these positions in a simulator, I have to convert them to cartesian coordinates.<br>
  For this I use the python package pyproj.</p>
  
  <pre><code>lat1 = 50.0
  lon1 = 10.0
  lat2 = 50.5
  lon2 = 10.5
  
  x1, y1, z1 = wgs84_to_utm32(lat1, lon1, 0.0)
  x2, y2, z2 = wgs84_to_utm32(lat2, lon2, 0.0)
  
  print(distance_haversine(lat1, lon1, lat2, lon2))
  print(distance_cartesian(x1, y1, x2, y2))
  </code></pre>
  
  <p>the ouput is:</p>
  
  <pre><code>66012.5130481
  102485.874713
  </code></pre>
  
  <p>that is a difference of over 36 km.</p>
  
  <p>So my question is, how can I convert lat/lon coordinates so that the distances are preserved. I don't care for minimal error.</p>
  
  <p>EDIT:</p>
  
  <pre><code>#
  # Convert WGS84 (Geographic) coordinates to UTM32 (Germany)
  #
  def wgs84_to_utm(lat, lon, alt):
     wgs84 = Proj(init='epsg:4326')
     utm_de = Proj(init='epsg:32632')  # utm germany = 32
  
     return transform(wgs84, utm_de, lat, lon, alt)
  </code></pre>
  
  <p>EDIT2:<br>
  Okay to be clear, I know that I am trying to compare a distance on a sphere to a distance on a flat surface.</p>
  
  <p>But since I am simulating WLAN nodes, the distance between those nodes is crucial. But I have no other information than their lat/lon coordinates.</p>
  
  <p>How would I go about representing those lat/lon coordinates on a flat surface, so that the distances are preserved?</p>
  
  <p>EDIT3:</p>
  
  <pre><code>def distance_haversine(lat1, lon1, lat2, lon2):
      # approximate radius of earth in km
      R = 6373.0 * 1000
  
      lat1 = radians(lat1)
      lon1 = radians(lon1)
      lat2 = radians(lat2)
      lon2 = radians(lon2)
  
      dlon = lon2 - lon1
      dlat = lat2 - lat1
  
      a = sin(dlat / 2) ** 2 + cos(lat1) * cos(lat2) * sin(dlon / 2) ** 2
      c = 2 * atan2(sqrt(a), sqrt(1 - a))
  
      distance = R * c
  
      return distance
  
  
  def distance_cartesian(x1, y1, x2, y2):
      dx = x1 - x2
      dy = y1 - y2
  
      return sqrt(dx * dx + dy * dy)
  </code></pre>