Skip to content

Instantly share code, notes, and snippets.

@inoook
Created November 16, 2023 03:10
Show Gist options
  • Select an option

  • Save inoook/922cfc85befc63533055cedd6f930e56 to your computer and use it in GitHub Desktop.

Select an option

Save inoook/922cfc85befc63533055cedd6f930e56 to your computer and use it in GitHub Desktop.

Revisions

  1. inoook created this gist Nov 16, 2023.
    20 changes: 20 additions & 0 deletions Coordinates.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    /// <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;
    }