public void TestFromAngle() { AssertAreEqual(new UnitVector(1, 0), UnitVector.FromAngle(0)); AssertAreEqual(new UnitVector(0, 1), UnitVector.FromAngle(Math.PI / 2)); AssertAreEqual(new UnitVector(-1, 0), UnitVector.FromAngle(Math.PI)); AssertAreEqual(new UnitVector(0, -1), UnitVector.FromAngle((Math.PI / 2) * 3)); AssertAreEqual(new UnitVector(1, 0), UnitVector.FromAngle(Math.PI * 2)); AssertAreEqual(new UnitVector(0, 1), UnitVector.FromAngle(Math.PI * 2 + Math.PI / 2)); AssertAreEqual(new UnitVector(0, -1), UnitVector.FromAngle(-Math.PI / 2)); AssertAreEqual(new UnitVector(-1, 0), UnitVector.FromAngle(-Math.PI)); AssertAreEqual(new UnitVector(0, 1), UnitVector.FromAngle(-(Math.PI / 2) * 3)); AssertAreEqual(new UnitVector(1, 0), UnitVector.FromAngle(-Math.PI * 2)); AssertAreEqual(new UnitVector(0, -1), UnitVector.FromAngle(-Math.PI * 2 - Math.PI / 2)); }
public void TestSignedAngle() { var u = (new Vector(1, 0.5)).Unit; var a = u.ToAngle(); AssertAreEqual(u, UnitVector.FromAngle(a)); u = (new Vector(1, -0.5)).Unit; a = u.ToAngle(); AssertAreEqual(u, UnitVector.FromAngle(a)); u = (new Vector(-1, 0.5)).Unit; a = u.ToAngle(); AssertAreEqual(u, UnitVector.FromAngle(a)); u = (new Vector(-1, -0.5)).Unit; a = u.ToAngle(); AssertAreEqual(u, UnitVector.FromAngle(a)); }
public void TestRotate() { var pt1 = new Point(1, 1); var pt2 = new Point(2, 2); var pt1_1 = pt1.Rotate(UnitVector.FromAngle(Math.PI / 4), Point.Zero); var pt2_1 = pt2.Rotate(UnitVector.FromAngle(Math.PI / 4), Point.Zero); var a1 = (pt2_1 - pt1_1).Unit.ToAngle(); var pt1_2 = pt1.Rotate(UnitVector.FromAngle(Math.PI / 8), Point.Zero); var pt2_2 = pt2.Rotate(UnitVector.FromAngle(Math.PI / 8), Point.Zero); pt2_2 = pt2_2.Rotate(UnitVector.FromAngle(Math.PI / 8), pt1_2); var a2 = (pt2_2 - pt1_2).Unit.ToAngle(); Assert.AreEqual(a1, a2, Tol); }