Last active
August 24, 2023 22:26
-
-
Save Infinitusvoid/a268446c99ae36298680626942993b94 to your computer and use it in GitHub Desktop.
Unity : How to convert cartesian coordinates to spherical coordinates system ?
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 (float radius, float theta, float phi) EulerToSpherical(Vector3 p) | |
{ | |
float radius = Mathf.Sqrt(p.x * p.x + p.y * p.y + p.z * p.z); | |
float theta = Mathf.Acos(p.z / radius); | |
float phi = Mathf.Atan2(p.y, p.x); | |
return (radius, theta, phi); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment