Last active
May 9, 2018 09:58
-
-
Save inoook/9261394ddcf5954112c5a6504643af1a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public static Vector3 SetLatLonPosition(float r, float lat, float lon) | |
{ | |
float phi = (90-lat)*Mathf.Deg2Rad; | |
float theta = (lon)*Mathf.Deg2Rad; | |
float x = r * Mathf.Sin(phi) * Mathf.Cos(theta); | |
float z = r * Mathf.Sin(phi) * Mathf.Sin(theta); | |
float y = r * Mathf.Cos(phi); | |
Vector3 pos = new Vector3(x,y,z); | |
return pos; | |
} | |
public static Vector2 GetLatLonFromVector3 (Vector3 position, float sphereRadius){ | |
float lat = (float)Mathf.Acos(position.y / sphereRadius); //theta | |
float lon = (float)Mathf.Atan2(position.x, position.z); //phi | |
lat *= Mathf.Rad2Deg; | |
lon *= Mathf.Rad2Deg; | |
return new Vector2(lat, lon); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment