Skip to content

Instantly share code, notes, and snippets.

@inoook
Created November 16, 2023 03:10
Show Gist options
  • Save inoook/922cfc85befc63533055cedd6f930e56 to your computer and use it in GitHub Desktop.
Save inoook/922cfc85befc63533055cedd6f930e56 to your computer and use it in GitHub Desktop.
Equirectangular座標から球面の3D座標に変換する関数
/// <summary>
/// Equirectangular座標から球面の3D座標に変換する関数
/// </summary>
/// <param name="lon">経度(0から1の範囲)</param>
/// <param name="lat">緯度(0から1の範囲)</param>
/// <returns></returns>
Vector3 EquirectangularToSphereCoordinates(float lon, float lat)
{
float u = lon;
float v = lat;
// Equirectangular座標から球面の3D座標に変換
Vector3 sphereCoord = new Vector3(
-Mathf.Cos(u * 2 * Mathf.PI) * Mathf.Sin(v * Mathf.PI),
-Mathf.Cos(v * Mathf.PI),
Mathf.Sin(u * 2 * Mathf.PI) * Mathf.Sin(v * Mathf.PI)
);
return sphereCoord;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment