Created
July 18, 2017 05:15
-
-
Save neuman/8c7e96345795fc53e79351fb5daef245 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
o.centerOriginToTopLeft = (x, y, w, h) =>{ | |
return new THREE.Vector2((w/2)-x, (h/2)-y); | |
}; | |
o.latLonToVector3 = (lat, lng, radius) => { | |
// convert latitude / longitude to angles between 0 and 2*phi | |
var phi = (90 - lat) * Math.PI / 180; | |
var theta = (180 - lng) * Math.PI / 180; | |
// Calculate the xyz coordinate from the angles | |
var x = radius * Math.sin(phi) * Math.cos(theta); | |
var y = radius * Math.cos(phi); | |
var z = radius * Math.sin(phi) * Math.sin(theta); | |
return new THREE.Vector3(x,y,z); | |
//return new THREE.Vector3(x,y,-z); | |
}; | |
o.xyToLatLon = (x, y, width, height) => { | |
// We just linearly convert the image coordinated to the angular latitude and longitude coordinates. | |
// Then we center them so the (0,0) coordinate is at the center of the image | |
var lat = 90 - 180 * (y / height); // equirectangular projection | |
var lon = 360 * (x / width) -180; | |
return { | |
'lat':lat, | |
'lon':lon | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment