Skip to content

Instantly share code, notes, and snippets.

@Infinitusvoid
Last active August 24, 2023 22:26
Show Gist options
  • Save Infinitusvoid/a268446c99ae36298680626942993b94 to your computer and use it in GitHub Desktop.
Save Infinitusvoid/a268446c99ae36298680626942993b94 to your computer and use it in GitHub Desktop.
Unity : How to convert cartesian coordinates to spherical coordinates system ?
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