Skip to content

Instantly share code, notes, and snippets.

@openroomxyz
Created April 1, 2020 10:22
Show Gist options
  • Save openroomxyz/7ac1e4af5d7094dc7937eee48fe75b2b to your computer and use it in GitHub Desktop.
Save openroomxyz/7ac1e4af5d7094dc7937eee48fe75b2b to your computer and use it in GitHub Desktop.
Unity : How to convert from Cartesian to Polar 2d?
//Cartesian to polar 2d
float radius = Mathf.Sqrt((x * x) + (y * y));
float angle = Mathf.Atan2(y, x);
float angle = Mathf.Atan2(py, px) * Mathf.Rad2Deg; //To get degress much more usefull
//TO get from zero to 1 angle / (float)(365)
https://docs.unity3d.com/ScriptReference/Mathf.Atan2.html
//It devision by zero not a problem it takes care of it xD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment