Skip to content

Instantly share code, notes, and snippets.

@nkjzm
Created June 8, 2018 08:51
Show Gist options
  • Save nkjzm/bd352549b7c4b6e34cc3b20558ca786e to your computer and use it in GitHub Desktop.
Save nkjzm/bd352549b7c4b6e34cc3b20558ca786e to your computer and use it in GitHub Desktop.
~∞ < θ < ∞ な角度θを -180 < θ < 180 に変換するコード
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