Skip to content

Instantly share code, notes, and snippets.

@zdavkeos
Created December 10, 2020 19:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zdavkeos/42541978d242bfd76606302e5fecb377 to your computer and use it in GitHub Desktop.
Save zdavkeos/42541978d242bfd76606302e5fecb377 to your computer and use it in GitHub Desktop.
// Euler Spiral map projection
// For https://tmcw.github.io/projectityourself/
let lon_look = [
[-180, -89.33633981999999],
[-177, -80.661710898],
[-174, -73.825305678],
[-171, -70.20639653399999],
[-167.99999999999997, -70.475119848],
[-165, -74.51836227],
[-162.00000000000003, -81.525147768],
[-159, -90.192768336],
[-156, -98.99807815800001],
[-152.99999999999997, -106.47557963999999],
[-150, -111.452716044],
[-147.00000000000003, -113.208958206],
[-144, -111.54419368199999],
[-141, -106.759551636],
[-137.99999999999997, -99.56729546999999],
[-135, -90.954400824],
[-132.00000000000003, -82.026830178],
[-129, -73.859223384],
[-126, -67.369204692],
[-122.99999999999999, -63.22838022],
[-120, -61.814822111999995],
[-117, -63.205511867999995],
[-114, -67.202517204],
[-111, -73.38385639799999],
[-108, -81.168978474],
[-105, -89.889241428],
[-102, -98.85526925399999],
[-99, -107.41515921],
[-96, -114.99978303],
[-93, -121.153563018],
[-90, -125.550892818],
[-87, -127.999702332],
[-83.99999999999999, -128.434513914],
[-81.00000000000001, -126.901737774],
[-78, -123.53999138999998],
[-75, -118.557992088],
[-72, -112.21216533],
[-68.99999999999999, -104.785618572],
[-66.00000000000001, -96.569623998],
[-63, -87.848283276],
[-60, -78.886646532],
[-57, -69.922241568],
[-54, -61.159741992],
[-51, -52.76835702],
[-48, -44.881450758],
[-45, -37.597880016],
[-41.99999999999999, -30.984562422000003],
[-39, -25.07983587],
[-36, -19.897237332],
[-33.00000000000001, -15.4293997194],
[-30, -11.6518379148],
[-27, -8.5264599978],
[-24, -6.0046978788],
[-20.999999999999996, -4.0301990514],
[-18, -2.5410596418],
[-15, -1.4716080424800002],
[-12, -0.7537696491600001],
[-9, -0.31805787672],
[-6, -0.09424611856800001],
[-3, -0.0117809594748],
[0, 0],
[3, 0.0117809594748],
[6, 0.09424611856800001],
[9, 0.31805787672],
[12, 0.7537696491600001],
[15, 1.4716080424800002],
[18, 2.5410596418],
[20.999999999999996, 4.0301990514],
[24, 6.0046978788],
[27, 8.5264599978],
[30, 11.6518379148],
[33.00000000000001, 15.4293997194],
[36, 19.897237332],
[39, 25.07983587],
[41.99999999999999, 30.984562422000003],
[45, 37.597880016],
[48, 44.881450758],
[51, 52.76835702],
[54, 61.159741992],
[57, 69.922241568],
[60, 78.886646532],
[63, 87.848283276],
[66.00000000000001, 96.569623998],
[68.99999999999999, 104.785618572],
[72, 112.21216533],
[75, 118.557992088],
[78, 123.53999138999998],
[81.00000000000001, 126.901737774],
[83.99999999999999, 128.434513914],
[87, 127.999702332],
[90, 125.550892818],
[93, 121.153563018],
[96, 114.99978303],
[99, 107.41515921],
[102, 98.85526925399999],
[105, 89.889241428],
[108, 81.168978474],
[111, 73.38385639799999],
[114, 67.202517204],
[117, 63.205511867999995],
[120, 61.814822111999995],
[122.99999999999999, 63.22838022],
[126, 67.369204692],
[129, 73.859223384],
[132.00000000000003, 82.026830178],
[135, 90.954400824],
[137.99999999999997, 99.56729546999999],
[141, 106.759551636],
[144, 111.54419368199999],
[147.00000000000003, 113.208958206],
[150, 111.452716044],
[152.99999999999997, 106.47557963999999],
[156, 98.99807815800001],
[159, 90.192768336],
[162.00000000000003, 81.525147768],
[165, 74.51836227],
[167.99999999999997, 70.475119848],
[171, 70.20639653399999],
[174, 73.825305678],
[177, 80.661710898],
[180, 89.33633981999999],
];
let lat_look = [
[-90, -54.514871037],
[-88.5, -53.479565874],
[-87, -50.613880518],
[-85.5, -46.535394951],
[-83.99999999999999, -42.074248653],
[-82.5, -38.093741666999996],
[-81.00000000000001, -35.324457291],
[-79.5, -34.241917176],
[-78, -35.004374658],
[-76.49999999999999, -37.45328472],
[-75, -41.167170864],
[-73.50000000000001, -45.55181772899999],
[-72, -49.946526522],
[-70.5, -53.727138161999996],
[-68.99999999999999, -56.390553882000006],
[-67.5, -57.611178890999994],
[-66.00000000000001, -57.265744041],
[-64.5, -55.428261534],
[-63, -52.34077215000001],
[-61.49999999999999, -48.367769499],
[-60, -43.942806549000004],
[-58.5, -39.515098104],
[-57, -35.502348141],
[-55.5, -32.253994575],
[-54, -30.026963448],
[-52.5, -28.974154158],
[-51, -29.14441884],
[-49.5, -30.491831016000003],
[-48, -32.891551506],
[-46.5, -36.159527943],
[-45, -40.073505839999996],
[-43.5, -44.393275035],
[-41.99999999999999, -48.878620515],
[-40.50000000000001, -53.304007419],
[-39, -57.469540923000004],
[-37.5, -61.208166699],
[-36, -64.389395061],
[-34.49999999999999, -66.920042943],
[-33.00000000000001, -68.74259994],
[-31.5, -69.831856935],
[-30, -70.190406036],
[-28.5, -69.843550815],
[-27, -68.834071908],
[-25.5, -67.217190876],
[-24, -65.05597547100001],
[-22.5, -62.417339172],
[-20.999999999999996, -59.36871167100001],
[-19.5, -55.975396851],
[-18, -52.29859023],
[-16.500000000000004, -48.39399774899999],
[-15, -44.310980330999996],
[-13.5, -40.092140583],
[-12, -35.773268328],
[-10.499999999999998, -31.383566478],
[-9, -26.946087848999998],
[-7.5, -22.478323535999998],
[-6, -17.992895184],
[-4.5, -13.498313787],
[-3, -8.9997779367],
[-1.5, -4.4999930600999996],
[0, 0],
[1.5, 4.4999930600999996],
[3, 8.9997779367],
[4.5, 13.498313787],
[6, 17.992895184],
[7.5, 22.478323535999998],
[9, 26.946087848999998],
[10.499999999999998, 31.383566478],
[12, 35.773268328],
[13.5, 40.092140583],
[15, 44.310980330999996],
[16.500000000000004, 48.39399774899999],
[18, 52.29859023],
[19.5, 55.975396851],
[20.999999999999996, 59.36871167100001],
[22.5, 62.417339172],
[24, 65.05597547100001],
[25.5, 67.217190876],
[27, 68.834071908],
[28.5, 69.843550815],
[30, 70.190406036],
[31.5, 69.831856935],
[33.00000000000001, 68.74259994],
[34.49999999999999, 66.920042943],
[36, 64.389395061],
[37.5, 61.208166699],
[39, 57.469540923000004],
[40.50000000000001, 53.304007419],
[41.99999999999999, 48.878620515],
[43.5, 44.393275035],
[45, 40.073505839999996],
[46.5, 36.159527943],
[48, 32.891551506],
[49.5, 30.491831016000003],
[51, 29.14441884],
[52.5, 28.974154158],
[54, 30.026963448],
[55.5, 32.253994575],
[57, 35.502348141],
[58.5, 39.515098104],
[60, 43.942806549000004],
[61.49999999999999, 48.367769499],
[63, 52.34077215000001],
[64.5, 55.428261534],
[66.00000000000001, 57.265744041],
[67.5, 57.611178890999994],
[68.99999999999999, 56.390553882000006],
[70.5, 53.727138161999996],
[72, 49.946526522],
[73.50000000000001, 45.55181772899999],
[75, 41.167170864],
[76.49999999999999, 37.45328472],
[78, 35.004374658],
[79.5, 34.241917176],
[81.00000000000001, 35.324457291],
[82.5, 38.093741666999996],
[83.99999999999999, 42.074248653],
[85.5, 46.535394951],
[87, 50.613880518],
[88.5, 53.479565874],
[90, 54.514871037],
];
function project(x, y) {
let xx = 0;
let yy = 0;
for (let i = 0; i < lon_look.length; i++) {
if (i == lon_look.length-1) {
xx = lon_look[i][1];
break;
}
if (lon_look[i][0] <= x && lat_look[i+1][0] >= x) {
xx = (lon_look[i][1] + lon_look[i+1][1]) / 2.0;
break;
}
}
for (let i = 0; i < lat_look.length; i++) {
if (i == lat_look.length-1) {
yy = lat_look[i][1];
break;
}
if (lat_look[i][0] <= x && lat_look[i+1][0] >= x) {
yy = (lat_look[i][1] + lat_look[i+1][1]) / 2.0;
break;
}
}
return [xx, yy];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment