Skip to content

Commit

Permalink
add TripleProduct
Browse files Browse the repository at this point in the history
chuongmep committed Jan 20, 2023
1 parent 3c1addd commit de25af7
Showing 2 changed files with 33 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/GShark.Test.XUnit/Geometry/VectorTests.cs
Original file line number Diff line number Diff line change
@@ -67,6 +67,22 @@ public void It_Returns_The_Dot_Product_Between_Two_Vectors()
dotProduct.Should().Be(25);
}

[Fact]
public void TestReturnResultOfTripleProduct()
{
Vector3 v1 = new Vector3(1, 2, 3);
Vector3 v2 = new Vector3(4, 5, 6);
Vector3 v3 = new Vector3(7, 8, 9);
double result = v1.TripleProduct(v2, v3);
result.Should().Be(0);
Vector3 u1 = new Vector3(2, 3, -4);
Vector3 u2 = new Vector3(5, 1, 6);
Vector3 u3 = new Vector3(-7, 8, 9);
double result2 = u1.TripleProduct(u2, u3);
result2.Should().Be(-527);

}

[Fact]
public void It_Returns_The_Squared_Length_Of_A_Vector()
{
17 changes: 17 additions & 0 deletions src/GShark/Geometry/Vector3.cs
Original file line number Diff line number Diff line change
@@ -706,6 +706,23 @@ public static double DotProduct(Vector3 vector1, Vector3 vector2)
return result;
}


/// <summary>
/// The triple product of this vector and the two specified vectors.
/// </summary>
/// <param name="middle">The second vector.</param>
/// <param name="right">The third vector.</param>
/// <returns>The real number equal to the triple product.</returns>
///<remarks>
/// The scalar triple product is defined as the dot product of one of the vectors
/// with the cross product of the other two. Geometrically, this product is the (signed)
/// volume of the parallelepiped formed by the three vectors given.
/// </remarks>
public double TripleProduct(Vector3 middle, Vector3 right)
{
return DotProduct(this, CrossProduct(middle, right));
}

///<summary>
/// Determines whether this vector is perpendicular to another vector, within a provided angle tolerance.
///</summary>

0 comments on commit de25af7

Please sign in to comment.