1

I have a Winkel Tripel map that I need to place markers over. Im given the position of the markers in Latitude/ Longitude. So I need a way to convert it to X,Y.

I found some code (below), but when I tried it out, the plot of a 45ยบ diagonal line has a moderate s-curve to it. So it's obviously not correct.

Any help would be great. Im doing this in PHP, but I should be able to convert any language.

private function sinc($x){
    if($x == 0) return 1;
    return sin($x) / $x;
}

private function winkelTripelToCartesian($lat, $lng){
    $lat = deg2rad($lat);
    $lng = deg2rad($lng);

    $alpha = acos(cos($lat) * cos($lng / 2));

    $x = ($lng * M_2_PI + (2 * cos($lat) * sin($lng / 2)) / $this->sinc($alpha)) / 2;
    $y = ($lat + (sin($lat) / $this->sinc($alpha))) / 2;

    return array('x'=> strval($x), 'y' => strval($y));
}
Adam Meyer
  • 1,505
  • 1
  • 19
  • 28

1 Answers1

0

That map projection tries to show an orb as a 2D-object, this causes it to change the way shapes look. It's possible that caused your line to bend.

If you're still not shure, here is a script I use to plot markers on a map with winkel III projection using Javascript:

  // latitudes/longitudes to radians
  var latRadian = (latitudes[i] * Math.PI) / 180;
  var lngRadian = (longitudes[e] * Math.PI) / 180;
  console.log("Radian Coordinates = " + latRadian + ", " + lngRadian);

  //Radians to xy cartesian coordinates
  var alpha = Math.acos( Math.cos(latRadian) * Math.cos( lngRadian / 2 ) );
  var phi_1 = Math.acos( 2 / Math.PI );
  function sinc(x) {
      if (x == 0) {
          return 1;
      } else {
          return (Math.sin(x)/x);
      }
  }
  var x = (svgHeight/Math.PI) * ( lngRadian * Math.cos(phi_1) + 2 * ( Math.cos(latRadian) * Math.sin(lngRadian/2) / sinc(alpha) ) ) / 2;
  var y = (svgHeight/Math.PI) * ( latRadian + ( Math.sin(latRadian) / sinc(alpha) )) / 2;

You can find the full example here: http://codepen.io/StinoM/pen/PZjYqw?editors=001

And here is some code I found that uses Ruby: https://gist.github.com/duncanbeevers/195554