Exemple #1
0
 private void DefineTriangles()
 {
     TriangleManager.Triangles = new List <Triangle>();
     NodManager.Noduri         = new List <Nod>();
     DrumManager.Drumuri       = new List <Drum>();
     foreach (var s in SegmentsManager.Segments)
     {
         var listFirstSegments  = SegmentsManager.GetSegmentsThatContainsASpecificPoint(s.A);
         var listSecondSegments = SegmentsManager.GetSegmentsThatContainsASpecificPoint(s.B);
         listFirstSegments.Remove(s);
         listSecondSegments.Remove(s);
         for (var i = 0; i < listFirstSegments.Count; i++)
         {
             var a = listFirstSegments[i].GetTheOtherPoint(s.A);
             for (var j = 0; j < listSecondSegments.Count; j++)
             {
                 var b = listSecondSegments[j].GetTheOtherPoint(s.B);
                 if (a.Equals(b))
                 {
                     var t = new Triangle(s.A, s.B, a);
                     if (!TriangleManager.CheckIfPointIsInsideTriangle(t) && !PolygonManager.CheckIfTriangleIsAShape(t))
                     {
                         if (TriangleManager.Triangles.Count > 0)
                         {
                             if (!TriangleManager.CheckIfTriangleAlreadyExists(t))
                             {
                                 TriangleManager.Triangles.Add(t);
                             }
                         }
                         else
                         {
                             TriangleManager.Triangles.Add(t);
                         }
                     }
                 }
             }
         }
     }
     foreach (var p in TriangleManager.Triangles.Select(tr => tr.GetGravityCenter()))
     {
         var n = new Nod(Id, p);
         if (NodManager.Noduri.Count > 0)
         {
             if (!NodManager.CheckIfNodExists(n))
             {
                 _g.FillEllipse(new SolidBrush(Color.Blue), p.X - 6, p.Y - 6, 12, 12);
                 NodManager.Noduri.Add(n);
                 Id++;
             }
         }
         else
         {
             _g.FillEllipse(new SolidBrush(Color.Blue), p.X - 6, p.Y - 6, 12, 12);
             NodManager.Noduri.Add(n);
             Id++;
         }
     }
 }
Exemple #2
0
        public static bool CanDraw(Point p, Point x)
        {
            var ls = SegmentsManager.GetSegmentsThatContainsASpecificPoint(p);
            var p1 = ls[0].GetTheOtherPoint(p);
            var p2 = ls[1].GetTheOtherPoint(p);
            var tr = new Triangle(p, p1, p2);

            if (TriangleManager.CheckIfAPointIsInsideATriangle(x, tr))
            {
                return(false);
            }
            return(true);
        }
Exemple #3
0
 public static bool CheckIfSegmentIntersectTwoPointsFromAnInternalShape(Segment s)
 {
     for (var i = 1; i < ListOfPolygons.Count; i++)
     {
         var lp = GetAllPolygonPoints(ListOfPolygons[i]);
         if (lp.Contains(s.A) && lp.Contains(s.B))
         {
             if (!SegmentsManager.CheckIfSegmentAlreadyExists(s))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Exemple #4
0
        private void b3_Click(object sender, EventArgs e)
        {
            try
            {
                _id        = "b3";
                b3.Checked = true;
                b1.Checked = false;
                b2.Checked = false;
                b4.Checked = false;
                b5.Checked = false;

                if (_spDefined && _epDefined)
                {
                    PolygonManager.ListOfPolygons = _polygons;
                    SegmentsManager.Segments      = PolygonManager.GetAllPolygonsSegments();
                    var allPoints = PolygonManager.GetAllPoints();
                    for (var i = 0; i < allPoints.Count; i++)
                    {
                        for (var j = 0; j < allPoints.Count; j++)
                        {
                            if (i != j)
                            {
                                var s = new Segment(allPoints[i], allPoints[j]);
                                if (!SegmentsManager.CheckIfSegmentAlreadyExists(s) &&
                                    IntersectieManager.CheckIfASegmentIntersectsAnotherSegment(s) &&
                                    !PolygonManager.CheckIfSegmentIntersectTwoPointsFromAnInternalShape(s))
                                {
                                    _g.DrawLine(new Pen(Color.Black), allPoints[i], allPoints[j]);
                                    SegmentsManager.Segments.Add(s);
                                }
                            }
                        }
                    }
                    DefineTriangles();
                    CreateGraph();
                    FindTheShortestPath();
                }
                else
                {
                    MessageBox.Show(@"StartPoint and EndPoint are not defined!");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }