public void dotProduct_NegativeValue() { vector = new Vector(1.0, 2.0, 3.0); vector2 = new Vector(-4.0, -25.0, -1.0); Assert.AreEqual((-4.0 -50.0 -3.0), vector.dotProduct(vector2)); vector2 = new Vector(-4.0, 5.0, 1.0); Assert.AreEqual((-4.0 + 10.0 + 3.0), vector.dotProduct(vector2)); }
public void dotProduct_AllGreaterThanTen() { vector = new Vector(12.0, 15.0, 20.0); vector2 = new Vector(20.0, 20.0, 20.0); Assert.AreEqual(((12.0 * 20.0) + (15.0 * 20.0) + (20.0 * 20.0)), vector.dotProduct(vector2)); }
/// <summary> /// Calculates the orthogonal projection of a vector on a differnet vector /// </summary> /// <param name="toVector">The vector which is projected upon</param> /// <returns>The projected vector</returns> public Vector orthogonalProjection(Vector toVector) { Vector returnVector = null; if (!((toVector.x == 0) && (toVector.y == 0) && (toVector.z == 0))) { double fraction = this.dotProduct(toVector) / toVector.dotProduct(toVector); returnVector = new Vector(fraction * toVector.x, fraction * toVector.y, fraction * toVector.z); } return returnVector; }
public void dotProduct_WithSelf() { vector = new Vector(1.0, 2.0, 3.0); Assert.AreEqual(1+4+9, vector.dotProduct(vector)); }
public void dotProduct_WithNull() { vector = new Vector(1.0, 2.0, 3.0); vector2 = null; Assert.AreEqual(0.0, vector.dotProduct(vector2)); vector2.dotProduct(vector); }
public void dotProduct_AllZero() { vector = new Vector(0.0, 0.0, 0.0); Assert.AreEqual(0.0, vector.dotProduct(vector)); }
public void orthogonalProjection_NegativeValues() { vector = new Vector(1.0, 2.0, 3.0); vector2 = new Vector(-4.0, -25.0, -1.0); double fraction = vector.dotProduct(vector2)/vector2.dotProduct(vector2); Vector newVector = new Vector (fraction*(-4.0), (-25.0) * fraction, (-1.0)* fraction); Assert.IsTrue(newVector.Equals(vector.orthogonalProjection(vector2))); }
public void orthogonalProjection_AllGreaterThanTen() { vector = new Vector(12.0, 15.0, 20.0); vector2 = new Vector(20.0, 20.0, 20.0); double fraction = vector.dotProduct(vector2) / vector.dotProduct(vector); Vector newVector = new Vector(12 * fraction, 15 * fraction, 20 * fraction); }
public void length_ValidInput() { vector = new Vector(-4.0, -25.0, -1.0); double expected = Math.Sqrt(vector.dotProduct(vector)); Assert.AreEqual(expected, vector.length()); vector2 = new Vector(12.0, 15.0, 20.0); expected = Math.Sqrt(vector2.dotProduct(vector2)); Assert.AreEqual(expected, vector2.length()); }