Esempio n. 1
0
 public override void Transform(PointIn2DIMSpace point)
 {
     for (int i = 0; i < Vertices.Length; i++)
     {
         var x        = point.X - Center.X;
         var y        = point.Y - Center.Y;
         var newpoint = new PointIn2DIMSpace(x, y);
         Vertices[i] += newpoint;
     }
 }
Esempio n. 2
0
        protected void UpdateCenter()
        {
            var sum = new PointIn2DIMSpace(0, 0);

            foreach (var point in Vertices)
            {
                sum += point;
            }
            Center = new PointIn2DIMSpace(sum.X / Vertices.Length, sum.Y / Vertices.Length);
        }
Esempio n. 3
0
 public Rectangle(string Name, PointIn2DIMSpace pointA, PointIn2DIMSpace pointB, PointIn2DIMSpace pointC, PointIn2DIMSpace pointD)
 {
     this.Name     = Name;
     NumberOfSides = 4;
     Vertices      = new PointIn2DIMSpace[NumberOfSides];
     Vertices[0]   = pointA;
     Vertices[1]   = pointB;
     Vertices[2]   = pointC;
     Vertices[3]   = pointD;
     UpdateCenter();
 }
Esempio n. 4
0
 public Diamond(string Name, PointIn2DIMSpace pointA, PointIn2DIMSpace pointB,
                PointIn2DIMSpace pointC, PointIn2DIMSpace pointD, PointIn2DIMSpace pointE)
 {
     this.Name          = Name;
     Vertices           = new PointIn2DIMSpace[5];
     this.NumberOfSides = 5;
     Vertices[0]        = pointA;
     Vertices[1]        = pointB;
     Vertices[2]        = pointC;
     Vertices[3]        = pointD;
     Vertices[4]        = pointE;
     UpdateCenter();
 }
Esempio n. 5
0
        //public void Draw()
        //{
        //    double temp;
        //    double[] distance = new double[ListOfShapes.Count];
        //    var lista = new List<Shape>(ListOfShapes);
        //    // init array with distances
        //    for (var i = 0; i < ListOfShapes.Count; i++)
        //    distance[i] = (Math.Pow(ListOfShapes[i].Center.X, 2) + Math.Pow(ListOfShapes[i].Center.Y, 2));
        //    // sort distances
        //    for (var i = 0; i < ListOfShapes.Count ; i++)
        //    {
        //        for (var j = i + 1; j < ListOfShapes.Count; j++)
        //        {
        //            if (distance[i] >= distance[j])
        //            {
        //                temp = distance[j];
        //                distance[j] = distance[i];
        //                distance[i] = temp;


        //                var tmpLista = lista[j];
        //                lista[j] = lista[i];
        //                lista[i] = tmpLista;

        //            }
        //        }
        //     lista[i].Draw();
        //    }
        //}

        #endregion

        public void Transform(int index, PointIn2DIMSpace point)
        {
            _log.WriteLine("asd " + ListOfShapes[index].Name);

            var x        = ListOfShapes[index].Center.X + point.X;
            var y        = ListOfShapes[index].Center.Y + point.Y;
            var newpoint = new PointIn2DIMSpace(x, y);

            //
            ListOfShapes[index].Center = newpoint;

            ListOfShapes[index].Transform(point);
        }
Esempio n. 6
0
  { static void Main(string[] args)
    {
        var point1 = new PointIn2DIMSpace(2.0, 3.0);
        var point2 = new PointIn2DIMSpace(6.0, 5.0);
        var point3 = new PointIn2DIMSpace(9.0, 4.5);
        var point4 = new PointIn2DIMSpace(4.5, 5.6);
        var point5 = new PointIn2DIMSpace(6.5, 9.6);
        // collection initializer
        var shapes = new List <Shape>
        {
            new Triangle("Triangle", point1, point2, point3),
            new EquilateralTriangle("EquilateralTriangle", point1, point2, point3),
            new IsoscelesTriangle("IsoscelesTriangle", point1, point2, point3),
            new Rectangle("Rectangle", point1, point2, point3, point4),
            new Circle("Circle", -9.0, -1.0, 5.0),
            new Diamond("Diamond", point1, point2, point3, point4, point5),
            new Ellipse("Ellipse", -10.0, 10.0, 5.2, 4.5)
        };

        foreach (var shape in shapes)
        {
            shape.ShapeChanged += ShapeOnShapeChanged;
        }
        ShapeContainer sc = new ShapeContainer(new TextFileLogger(), shapes);

        var newPointTransform = new PointIn2DIMSpace(15.0, 41.0);

        foreach (var shape in shapes)
        {
            Console.WriteLine(shape.Name);
            Console.WriteLine("The point is in (" + shape.Center.X + "," + shape.Center.Y + ")");
            Console.WriteLine("Perimeter is: " + shape.Perimeter());
            Console.WriteLine("Area is: " + shape.Area());

            shape.Draw();
            shape.Quadrant();
            if (shape.GetType() == typeof(IDisplay))
            {
                ((IDisplay)shape).Display();
            }
            shapes[0].Transform(newPointTransform);
        }
        Console.WriteLine("The minimum number of rays :   " + RayTrace(shapes));
        Console.ReadLine();
    }
Esempio n. 7
0
 public Shape(double x, double y)
 {
     Center = new PointIn2DIMSpace(x, y);
 }
Esempio n. 8
0
 public double DistanceToPoint(PointIn2DIMSpace pt)
 {
     return(Math.Sqrt(Math.Pow(pt.X - X, 2) + Math.Pow(pt.Y - Y, 2)));
 }