Created
April 1, 2020 10:22
-
-
Save openroomxyz/7ac1e4af5d7094dc7937eee48fe75b2b to your computer and use it in GitHub Desktop.
Unity : How to convert from Cartesian to Polar 2d?
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
//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