예제 #1
0
 public Triangle(TriangleCoord A, TriangleCoord B, TriangleCoord C)
 {
     if (A == B && A == C)
     {
         throw new Exception("Error: at least 1 point must be different");
     }
     else
     {
         this.A = A;
         this.B = B;
         this.C = C;
         AB     = Math.Round(Math.Sqrt(Math.Pow((B.X - A.X), 2) + Math.Pow((B.Y - A.Y), 2)), 1);
         BC     = Math.Round(Math.Sqrt(Math.Pow((C.X - B.X), 2) + Math.Pow((C.Y - B.Y), 2)), 1);
         AC     = Math.Round(Math.Sqrt(Math.Pow((C.X - A.X), 2) + Math.Pow((C.Y - A.Y), 2)), 1);
     }
 }
예제 #2
0
        static void Main(string[] args)
        {
            try
            {
                Triangle ABC = new Triangle(new TriangleCoord(1, 1), new TriangleCoord(5, 8), new TriangleCoord(-4, -1));
                ABC.Show();
                Console.WriteLine("Perimeter: " + ABC.Perimeter());
                Console.WriteLine("Area: " + ABC.Area());

                TriangleCoord MedCrosPt = Triangle.MedianCrossingPt(ABC);
                Console.Write("Median crossing point: ");
                MedCrosPt.Show();

                //Triangle WTF = new Triangle(new TriangleCoord(1, 1), new TriangleCoord(1, 1), new TriangleCoord(1, 1));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }