Created
June 8, 2018 08:51
-
-
Save nkjzm/bd352549b7c4b6e34cc3b20558ca786e to your computer and use it in GitHub Desktop.
~∞ < θ < ∞ な角度θを -180 < θ < 180 に変換するコード
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 class MathUtility | |
{ | |
public static int Mod(float a, float b) | |
{ | |
return (int)(a - Mathf.Floor(a / b) * b); | |
} | |
// 角度を-180<x<180に変換 | |
public static float FixedAngle(float angle) | |
{ | |
var modAngle = Mod(angle, 360f); | |
return (modAngle <= 180f ? modAngle : modAngle - 360f); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment