/// <summary>
 /// Calculates the cosine of <paramref name="angle"/> in <paramref name="tri"/>.
 /// </summary>
 /// <param name="tri">The triangle</param>
 /// <param name="angle">The angle to calculate.</param>
 /// <returns>The cosine of <paramref name="angle"/>.</returns>
 public static double Cosine(Triangle tri, TriangleAngle angle = TriangleAngle.C)
 {
     switch (angle)
     {
         case TriangleAngle.A:
             return tri.SideA / tri.SideC;
         default:
             return tri.AngleB / tri.SideC;
     }
 }
 /// <summary>
 /// Calculates the tangent of <paramref name="angle"/> in <paramref name="tri"/>.
 /// </summary>
 /// <param name="tri">The triangle</param>
 /// <param name="angle">The angle to calculate.</param>
 /// <returns>The tangent of <paramref name="angle"/>.</returns>
 public static double Tangent(Triangle tri, TriangleAngle angle = TriangleAngle.C)
 {
     switch (angle)
     {
         case TriangleAngle.A:
             return tri.SideB / tri.SideA;
         default:
             return tri.AngleA / tri.SideB;
     }
 }
Beispiel #3
0
        public void TriangleTest()
        {
            Triangle triangle = new Triangle(length:5, height:6);

            Assert.AreEqual(5, triangle.SideA);
            Assert.AreEqual(6, triangle.SideB);
            Assert.AreEqual(15, triangle.Area);

            RightTriangle triangle2 = new RightTriangle(5, 6);

            Assert.AreEqual(triangle, triangle2);
            Assert.AreEqual(triangle.Perimeter, triangle2.Perimeter);

            Triangle triangle3 = new Triangle(sideB:4,sideC:5,angleC:90);
            Assert.AreEqual(triangle3.Area, 6);
            Assert.AreEqual(12, triangle3.Perimeter);
            Triangle triangle4 = new Triangle(sideB: 3, sideC: 3, angleC: 60);
            Assert.AreEqual(9, triangle4.Perimeter);

            /*
            try
            {
                Triangle wrongTriangle = new Triangle(1,6,10);
                Assert.Fail("This triangle should've thrown an exception!");
            }
            catch (Mathos.Exceptions.InvalidTriangleException)
            {
            }
             */
        }
Beispiel #4
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public bool Equals(Triangle other)
 {
     return other != null && (Math.Abs(_sideA - other._sideA) < 1 && Math.Abs(_sideB - other._sideB) < 1 &&
                              Math.Abs(_sideC - other._sideC) < 1 && Math.Abs(_angleA - other._angleA) < 1 &&
                              Math.Abs(_angleB - other._angleB) < 1 && Math.Abs(_angleC - other._angleC) < 1);
 }