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++; } } }
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); }
private void CreateGraph() { foreach (var t in TriangleManager.Triangles) { var mainT = t; var a = mainT.GetGravityCenter(); var trianglesNextToMaintT = TriangleManager.GetAllTrianglesNextToMainTriangle(mainT); foreach (var tr in trianglesNextToMaintT) { var b = tr.GetGravityCenter(); var seg = TriangleManager.GetCommonSegmentFromTwoTriangles(t, tr); if (IntersectieManager.CheckIfTwoPointsIntersectOnlyASpecificSegment(a, b, seg)) { Drum d = new Drum(NodManager.GetNod(a), NodManager.GetNod(b), new Segment(a, b).GetLength()); if (!DrumManager.CheckIfDrumExists(d)) { _g.DrawLine(new Pen(Color.Blue), a, b); DrumManager.Drumuri.Add(d); } } else if (IntersectieManager.CheckIfTwoPointsIntersectAShape(a, b)) { var n = new Nod(Id, seg.GetTheMiddlePoint()); if (!NodManager.CheckIfNodExists(n)) { _g.FillEllipse(new SolidBrush(Color.Blue), seg.GetTheMiddlePoint().X - 6, seg.GetTheMiddlePoint().Y - 6, 12, 12); NodManager.Noduri.Add(n); Id++; } Drum d1 = new Drum(NodManager.GetNod(a), NodManager.GetNod(seg.GetTheMiddlePoint()), new Segment(a, seg.GetTheMiddlePoint()).GetLength()); if (!DrumManager.CheckIfDrumExists(d1)) { _g.DrawLine(new Pen(Color.Blue), a, seg.GetTheMiddlePoint()); DrumManager.Drumuri.Add(d1); } Drum d2 = new Drum(NodManager.GetNod(seg.GetTheMiddlePoint()), NodManager.GetNod(b), new Segment(seg.GetTheMiddlePoint(), b).GetLength()); if (!DrumManager.CheckIfDrumExists(d2)) { _g.DrawLine(new Pen(Color.Blue), seg.GetTheMiddlePoint(), b); DrumManager.Drumuri.Add(d2); } } } } }
private void FindTheShortestPath() { Pen greenPen = new Pen(Color.Purple, 3); var tr1 = TriangleManager.ReturnTriangleWithAPointInside(_startPoint); var tr2 = TriangleManager.ReturnTriangleWithAPointInside(_endPoint); var gr1 = tr1.GetGravityCenter(); var gr2 = tr2.GetGravityCenter(); _g.DrawLine(greenPen, _startPoint, gr1); _g.DrawLine(greenPen, _endPoint, gr2); var startNod = NodManager.GetNod(gr1); var endNod = NodManager.GetNod(gr2); var gr = new Graph(); foreach (var n in NodManager.Noduri) { var dict = new Dictionary <char, int>(); var nodesThatCanBeReached = NodManager.CheckWehereANodCanGo(n); foreach (var nd in nodesThatCanBeReached) { dict.Add(nd.Id, Convert.ToInt32(new Segment(n.P, nd.P).GetLength())); } gr.add_vertex(n.Id, dict); } var ls = gr.shortest_path(startNod.Id, endNod.Id); if (ls.Count > 0) { _g.DrawLine(greenPen, startNod.P, NodManager.GetNodWithId(ls[ls.Count - 1]).P); for (var i = 0; i < ls.Count() - 1; i++) { var n = NodManager.GetNodWithId(ls[i]); var n2 = NodManager.GetNodWithId(ls[i + 1]); _g.DrawLine(greenPen, n.P, n2.P); } } }