private PVector GetNewDrawingPoint(PVector p, PVector next, int n) { var rnd = new Random(n*10); var rndx2 = new Random(n * 452); var rndy = new Random(n * 70); var rndy2 = new Random(n * 750); PVector direction = PVector.Sub(next, p); PVector newPosition = direction.Copy(); newPosition.SetMag((GetRandomized(rnd, rndx2) - 0.5) * _BrushInfoService.XDispersion); PVector ymov = direction.Copy(); ymov.RotateDegrees(90); ymov.SetMag((GetRandomized(rndy, rndy2) - 0.5) * _BrushInfoService.YDispersion); newPosition.Add(ymov); newPosition.Add(p); return newPosition; }
public void ShouldStaticallyLinearInterpoleTwoVectorsByGivenAmmountAndDontChangeOriginalVectors() { PVector vectorA = new PVector(1, 2, 3); PVector vectorACopy = vectorA.Copy(); PVector vectorB = new PVector(5, 6, 7); PVector vectorBCopy = vectorB.Copy(); float ammount = 0.5f; PVector resultVector = PVector.Lerp(vectorA, vectorB, ammount); // vectorA should not be changed Assert.Equal(vectorACopy.X, vectorA.X); Assert.Equal(vectorACopy.Y, vectorA.Y); Assert.Equal(vectorACopy.Z, vectorA.Z); // vectorB should not be changed Assert.Equal(vectorBCopy.X, vectorB.X); Assert.Equal(vectorBCopy.Y, vectorB.Y); Assert.Equal(vectorBCopy.Z, vectorB.Z); Assert.NotNull(resultVector); Assert.Equal(3f, resultVector.X); Assert.Equal(4f, resultVector.Y); Assert.Equal(5f, resultVector.Z); }
public void ShouldSetMagnitudeOfTargetVectorWithoutChangingActualVector() { PVector vectorA = new PVector(1, 2, 2); float originalVectorAMagnitude = vectorA.Mag(); // Magnitude 3 PVector vectorACopy = vectorA.Copy(); PVector targetVector = new PVector(3, 4, 0); float originalTargetVectorMagnitude = targetVector.Mag(); // Magnitude 5 float desiredNewMagnitude = 8f; PVector resultVector = vectorA.SetMag(targetVector, desiredNewMagnitude); float resultMagnitude = resultVector.Mag(); //Vector A should not change Assert.Equal(originalVectorAMagnitude, vectorA.Mag()); Assert.Equal(vectorACopy.X, vectorA.X); Assert.Equal(vectorACopy.Y, vectorA.Y); Assert.Equal(vectorACopy.Z, vectorA.Z); Assert.Same(targetVector, resultVector); Assert.NotEqual(originalTargetVectorMagnitude, resultMagnitude); Assert.Equal(desiredNewMagnitude, resultMagnitude); }
public void ShouldCopyComponentsFrom3dVector() { PVector originalVector = new PVector(10, 20.30f, 40.5678f); PVector copyVector = originalVector.Copy(); Assert.NotEqual(originalVector, copyVector); Assert.Equal(originalVector.X, copyVector.X); Assert.Equal(originalVector.Y, copyVector.Y); Assert.Equal(originalVector.Z, copyVector.Z); }
public void ShouldReturnNormalizedVectorWithoutChangingActrualVector() { PVector vectorA = new PVector(3, 4, 5); PVector vectorACopy = vectorA.Copy(); float originalMagnitude = vectorA.Mag(); PVector targetVector = new PVector(5, 5, 5); PVector normalizedVector = vectorA.Normalize(targetVector); //Vector A should not change Assert.Equal(originalMagnitude, vectorA.Mag()); Assert.Equal(vectorACopy.X, vectorA.X); Assert.Equal(vectorACopy.Y, vectorA.Y); Assert.Equal(vectorACopy.Z, vectorA.Z); Assert.Same(normalizedVector, targetVector); Assert.NotEqual(1f, targetVector.Mag()); }
public void ShouldCalculateDotProductOfTwoVectors() { PVector aVector = new PVector(3, 4, 5); PVector copyOfA = aVector.Copy(); PVector bVector = new PVector(1, 2, 3); PVector copyOfB = bVector.Copy(); float dotProduct = PVector.Dot(aVector, bVector); Assert.Equal(26f, dotProduct); Assert.Equal(copyOfA.X, aVector.X); Assert.Equal(copyOfA.Y, aVector.Y); Assert.Equal(copyOfA.Z, aVector.Z); Assert.Equal(copyOfB.X, bVector.X); Assert.Equal(copyOfB.Y, bVector.Y); Assert.Equal(copyOfB.Z, bVector.Z); }
public Segment(PVector a_, PVector b_) { a = a_.Copy(); b = b_.Copy(); }