public void SinCosからAtan2で元のAngleを復元() { void assert(Table.Angle angle) { var s1 = Table.Sin(angle); var c1 = Table.Cos(angle); var atan = Table.Atan2(s1, c1); var a1 = Table.Angle.FromRadian(atan); Assert.Equal(angle, a1); } for (int i = 0; i < 256; i++) { assert(new Table.Angle((byte)i)); } }
public void Atan2誤差1パーセント以下の精度で計算できる() { void assertYX(T y, T x) { var t1 = Table.Atan2(y, x); var t2 = M.Atan2(y, x); Assert.True(M.Abs(t1 - t2) < 2e-3); } void assert(T theta) { var(y, x) = (M.Cos(theta), M.Sin(theta)); assertYX(y, x); } var r = new Random(); for (int i = 0; i < 1000; i++) { var theta = r.NextDouble() * 1000 - 500; assert(theta); } for (int i = 0; i < 1000; i++) { var y = r.NextDouble() * 1000 - 500; var x = r.NextDouble() * 1000 - 500; assertYX(y, x); } foreach (var theta in _cornerCase) { assert(theta); } for (int x = -1; x <= 1; x++) { for (int y = -1; y <= 1; y++) { assertYX(x, y); } } }