public void ShouldReturnActualAngleOfVectorOnXYPlane() { PVector vectorA = new PVector(1, 1, 2); float theta = vectorA.Heading(); // PI/4 float expectedTheta = (float)Math.PI / 4; Assert.Equal(expectedTheta, theta); vectorA.Set(1, 0); theta = vectorA.Heading(); // 0 expectedTheta = 0f; Assert.Equal(expectedTheta, theta); vectorA.Set(0, 1); theta = vectorA.Heading(); // PI/2 expectedTheta = (float)Math.PI / 2; Assert.Equal(expectedTheta, theta); }
public void ShouldCreateASameRandom2DUnitVectorFromGivenRandomObjectAndSetTarget() { Random random = new Random(1); PVector target = new PVector(); PVector vectorA = PVector.Random2D(target, random); float angle = vectorA.Heading(); float expectedAngle = 1.56243074f; Assert.Same(target, vectorA); Assert.NotNull(vectorA); Assert.Equal(expectedAngle, angle); }
public void ShouldCreateASameRandom2DUnitVectorFromGivenRandomObject() { Random random = new Random(1); PVector vectorA = PVector.Random2D(random); float angle = vectorA.Heading(); float expectedAngle = 1.56243074f; Assert.NotNull(vectorA); Assert.Equal(expectedAngle, angle); random = new Random(1000); vectorA = PVector.Random2D(random); angle = vectorA.Heading(); expectedAngle = 0.9522636f; Assert.NotNull(vectorA); Assert.Equal(expectedAngle, angle); }
public void ShouldCreateUnitVectorFromGivenAngle() { float angle = (float)Math.PI / 2; PVector vectorA = PVector.FromAngle(angle); float calculatedAngle = vectorA.Heading(); float calculatedMagnitude = vectorA.Mag(); Assert.Equal(angle, calculatedAngle); float diff = (float)Math.Abs(1f - calculatedMagnitude); Assert.True(diff < ROUNDING_ERROR); angle = (float)Math.PI / 4; vectorA = PVector.FromAngle(angle); calculatedAngle = vectorA.Heading(); calculatedMagnitude = vectorA.Mag(); Assert.Equal(angle, calculatedAngle); diff = (float)Math.Abs(1f - calculatedMagnitude); Assert.True(diff < ROUNDING_ERROR); }