Esempio n. 1
0
 public float[] VectorTo(Cord T)
 {
     return(new float[2]
     {
         x - T.x,
         y - T.y
     });
 }
Esempio n. 2
0
 private void Set(Cord A, Cord B, Cord C)
 {
     this.A  = A.GetCord();
     this.B  = B.GetCord();
     this.C  = C.GetCord();
     this.BC = B.Distance(C);
     this.AC = A.Distance(C);
     this.AB = A.Distance(B);
 }
Esempio n. 3
0
        static void Main(string[] args)
        {
            Cord     c   = new Cord();
            Cord     b   = new Cord(5, 0);
            Cord     a   = new Cord(0, 5);
            Triangle tr1 = new Triangle(a, b, c);
            Triangle tr2 = new Triangle(new Cord(1, 1), new Cord(1, 5), new Cord(4, 1));

            tr1.Display("Tr1");
            tr2.Display("TR2");
            Console.WriteLine("TR1 == TR2 ? " + tr1.EqualTr(tr2));
            tr2.Rotation('A', 60);
            tr2.Display("Tr2");
            tr2.Rotation('A', -60);
            tr2.Display("Tr2");
            Console.ReadKey();
        }
Esempio n. 4
0
        /// <summary>
        /// Повертає трикутник навколо точки pointName: (A,B,C, O - центр описаного кола) на кут angle в градусах
        /// </summary>
        /// <returns></returns>
        public void Rotation(char pointName, int angle)
        {
            Console.WriteLine($"Rotation by a {angle} degrees relative to a point \'" + pointName + "\'.");
            Cord centerOfRotation;

            switch (pointName)
            {
            case 'A':
            case 'a':
                centerOfRotation = A.GetCord();
                break;

            case 'B':
            case 'b':
                centerOfRotation = B.GetCord();
                break;

            case 'C':
            case 'c':
                centerOfRotation = C.GetCord();
                break;

            case 'O':
            case 'o':
                float znam = 2 * (A.X * (B.Y - C.Y) + B.X * (C.Y - A.Y) + C.X * (A.Y - B.Y));
                float x    = (A.Y * DSSC(B, C) + B.Y * DSSC(C, A) + C.Y * DSSC(A, B)) / (-2 * znam);
                float y    = (A.X * DSSC(B, C) + B.X * DSSC(C, A) + C.X * DSSC(A, B)) / znam;
                centerOfRotation = new Cord(x, y);
                break;

            default: return;
            }
            float cos_angle = (float)Math.Cos(angle * Math.PI / 180);
            float sin_angle = (float)Math.Sin(angle * Math.PI / 180);
            float Ax        = centerOfRotation.X + (A.X - centerOfRotation.X) * cos_angle - (A.Y - centerOfRotation.Y) * sin_angle;
            float Ay        = centerOfRotation.Y + (A.Y - centerOfRotation.Y) * cos_angle + (A.X - centerOfRotation.X) * sin_angle;
            float Bx        = centerOfRotation.X + (B.X - centerOfRotation.X) * cos_angle - (B.Y - centerOfRotation.Y) * sin_angle;
            float By        = centerOfRotation.Y + (B.Y - centerOfRotation.Y) * cos_angle + (B.X - centerOfRotation.X) * sin_angle;
            float Cx        = centerOfRotation.X + (C.X - centerOfRotation.X) * cos_angle - (C.Y - centerOfRotation.Y) * sin_angle;
            float Cy        = centerOfRotation.Y + (C.Y - centerOfRotation.Y) * cos_angle + (C.X - centerOfRotation.X) * sin_angle;

            Set(new Cord(Ax, Ay), new Cord(Bx, By), new Cord(Cx, Cy));
        }
Esempio n. 5
0
 public float Distance(Cord T)
 {
     return((float)Math.Sqrt(Math.Pow(T.x - this.x, 2) + Math.Pow(T.y - this.y, 2)));
 }
Esempio n. 6
0
 /// <summary>
 /// difference of the sum of squares of coordinates: повертає різницю між сумю кватратів координат точки Т1 та Т2
 /// </summary>
 /// <returns></returns>
 private float DSSC(Cord T1, Cord T2)
 {
     return(T1.X * T1.X + T1.Y * T1.Y - T2.X * T2.X - T2.Y * T2.Y);
 }
Esempio n. 7
0
 public Triangle(Cord A, Cord B, Cord C)
 {
     Set(A, B, C);
 }