Exemple #1
0
        public static void Draw_Triangle(Dreieck dreieck, Canvas target)
        {
            Polygon triangle = new Polygon();
            var     points   = new PointCollection();

            triangle.Stroke          = Brushes.Black;
            triangle.StrokeThickness = 1;
            triangle.Fill            = Brushes.OrangeRed;

            points.Add(dreieck.PunktA);
            points.Add(dreieck.PunktB);
            points.Add(dreieck.PunktC);
            triangle.Points = points;

            triangle.MouseEnter += OnTriangleHover;
            triangle.MouseLeave += OnTriangleAway;

            target.Children.Add(triangle);
        }
Exemple #2
0
        public static void Generate_Triangle(Point pt1, string direction, Canvas canvas)
        {
            Dreieck temp = new Dreieck();

            temp.PunktA = pt1;

            switch (direction)
            {
            case "rd":
                temp.PunktB      = new Point(pt1.X + 1, pt1.Y);
                temp.PunktC      = new Point(pt1.X + 1, pt1.Y + 1);
                temp.Orientation = 3;
                break;

            case "ru":
                temp.PunktB      = new Point(pt1.X + 1, pt1.Y);
                temp.PunktC      = new Point(pt1.X + 1, pt1.Y - 1);
                temp.Orientation = 2;
                break;

            case "ld":
                temp.PunktB      = new Point(pt1.X - 1, pt1.Y);
                temp.PunktC      = new Point(pt1.X - 1, pt1.Y + 1);
                temp.Orientation = 4;
                break;

            case "lu":
                temp.PunktB      = new Point(pt1.X - 1, pt1.Y);
                temp.PunktC      = new Point(pt1.X - 1, pt1.Y - 1);
                temp.Orientation = 1;
                break;

            case "dr":
                temp.PunktB      = new Point(pt1.X, pt1.Y + 1);
                temp.PunktC      = new Point(pt1.X + 1, pt1.Y + 1);
                temp.Orientation = 1;
                break;

            case "ur":
                temp.PunktB      = new Point(pt1.X, pt1.Y - 1);
                temp.PunktC      = new Point(pt1.X + 1, pt1.Y - 1);
                temp.Orientation = 4;
                break;

            case "dl":
                temp.PunktB      = new Point(pt1.X, pt1.Y + 1);
                temp.PunktC      = new Point(pt1.X - 1, pt1.Y + 1);
                temp.Orientation = 2;
                break;

            case "ul":
                temp.PunktB      = new Point(pt1.X, pt1.Y - 1);
                temp.PunktC      = new Point(pt1.X - 1, pt1.Y - 1);
                temp.Orientation = 3;
                break;

            case "q1":
                temp.PunktB      = new Point(pt1.X + 1, pt1.Y);
                temp.PunktC      = new Point(pt1.X, pt1.Y - 1);
                temp.Orientation = 1;
                break;

            case "q2":
                temp.PunktB      = new Point(pt1.X - 1, pt1.Y);
                temp.PunktC      = new Point(pt1.X, pt1.Y - 1);
                temp.Orientation = 2;
                break;

            case "q3":
                temp.PunktB      = new Point(pt1.X - 1, pt1.Y);
                temp.PunktC      = new Point(pt1.X, pt1.Y + 1);
                temp.Orientation = 3;
                break;

            case "q4":
                temp.PunktB      = new Point(pt1.X + 1, pt1.Y);
                temp.PunktC      = new Point(pt1.X, pt1.Y + 1);
                temp.Orientation = 4;
                break;

            default:
                break;
            }

            temp.Convert(leX, leY);

            if (Validate_Triangle(temp, canvas))
            {
                Draw_Triangle(temp, canvas);
                DreieckListe.Add(temp);
                //Controls(direction);
            }
        }
        public static bool Validate_Triangle(Dreieck _dreieck, Canvas canvas)
        {
            /* 1. Dreieck im Koordinatenbereich
             * 2. Dreieck noch nicht vorhanden
             * 3. Dreieck muss 2 Punkte mit einem Dreieck gemeinsam haben
             * 4. Dreieck darf andere Dreiecke nicht überlappen (Mehrzahl!!!)*/

            //1)
            if (_dreieck.GetMax().X >= canvas.Width | _dreieck.GetMax().Y >= canvas.Height | _dreieck.GetMin().X <= 0 | _dreieck.GetMin().Y <= 0)
            {
                return(false);
            }

            //2) und 3) und 4)
            var  PointListCurrentListItem = new List <Point>();
            var  samePoints = new List <Point>();
            var  eligibleDreieckeToAddTo = new List <Dreieck>();
            bool overlap = false;

            if (DreieckListe.Count > 0)
            {
                foreach (var listItem in DreieckListe)
                {
                    PointListCurrentListItem.Add(_dreieck.PunktA);
                    PointListCurrentListItem.Add(_dreieck.PunktB);
                    PointListCurrentListItem.Add(_dreieck.PunktC);
                    PointListCurrentListItem.Add(listItem.PunktA);
                    PointListCurrentListItem.Add(listItem.PunktB);
                    PointListCurrentListItem.Add(listItem.PunktC);


                    if (_dreieck.PunktA == listItem.PunktA | _dreieck.PunktA == listItem.PunktB | _dreieck.PunktA == listItem.PunktC)
                    {
                        samePoints.Add(_dreieck.PunktA);
                    }
                    if (_dreieck.PunktB == listItem.PunktA | _dreieck.PunktB == listItem.PunktB | _dreieck.PunktB == listItem.PunktC)
                    {
                        samePoints.Add(_dreieck.PunktB);
                    }
                    if (_dreieck.PunktC == listItem.PunktA | _dreieck.PunktC == listItem.PunktB | _dreieck.PunktC == listItem.PunktC)
                    {
                        samePoints.Add(_dreieck.PunktC);
                    }

                    switch (samePoints.Count)
                    {
                    case 2:    //3)
                        eligibleDreieckeToAddTo.Add(listItem);
                        switch (_dreieck.Orientation)
                        {
                        case 1:
                            if ((listItem.Orientation == 2 && _dreieck.GetMin().X != listItem.GetMax().X) | (listItem.Orientation == 4 && _dreieck.GetMax().Y != listItem.GetMin().Y))
                            {
                                overlap = true;
                            }
                            break;

                        case 2:
                            if ((listItem.Orientation == 1 && _dreieck.GetMax().X != listItem.GetMin().X) | (listItem.Orientation == 3 && _dreieck.GetMax().Y != listItem.GetMin().Y))
                            {
                                overlap = true;
                            }
                            break;

                        case 3:
                            if ((listItem.Orientation == 2 && _dreieck.GetMax().X == listItem.GetMax().X) | (listItem.Orientation == 4 && _dreieck.GetMin().Y == listItem.GetMin().Y))
                            {
                                overlap = true;
                            }
                            break;

                        case 4:
                            if ((listItem.Orientation == 1 && _dreieck.GetMin().X == listItem.GetMin().X) | (listItem.Orientation == 3 && _dreieck.GetMin().Y == listItem.GetMin().Y))
                            {
                                overlap = true;
                            }
                            break;
                        }
                        break;

                    case 3:    //2)
                        return(false);

                    default:
                        break;
                    }

                    samePoints.Clear();
                    PointListCurrentListItem.Clear();
                }
            }
            else //erstes dreieck
            {
                return(true);
            }

            if (eligibleDreieckeToAddTo.Count != 0 && !overlap)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }