private void VeDuong(Diem diemdau,Diem diemcuoi, Color cl) { SolidBrush myBrush = new SolidBrush(Color.Green); Graphics tengido = this.CreateGraphics(); Pen pen = new Pen(cl, 3); Font font = new Font("Arial", 15, FontStyle.Bold); tengido.DrawLine(pen,diemdau.A,diemdau.B,diemcuoi.A,diemcuoi.B ); //vẽ mũi tên if (CoHuong == true) { pen.EndCap = System.Drawing.Drawing2D.LineCap.Custom; pen.CustomEndCap = new System.Drawing.Drawing2D.AdjustableArrowCap(4, 4, true); } tengido.DrawLine(pen, diemdau.A, diemdau.B, (diemcuoi.A+diemdau.A)/2, (diemcuoi.B+diemdau.B)/2); // tengido.DrawLine(pen, x1, y1, x2, y2); //hủy pen.Dispose(); tengido.Dispose(); }
public void LuuDuongVaDiem(string _diem, string _diemdau, string _diemsau) { //Lưu đỉêm Diem diem = new Diem(); diem.Ten = _diem; LuuDiem.Add(diem); //Lưu đường DuongThang dt = new DuongThang(); Diem diemdau = new Diem(); diemdau.Ten = _diemdau; dt.DiemDau = diemdau; Diem diemsau = new Diem(); diemsau.Ten = _diemsau; dt.DiemCuoi = diemsau; LuuDuong.Add(dt); }
private void VeDijkstra_MouseDown(object sender, MouseEventArgs e) { //Vẽ điểm if (Dangve == true) { Diem diem = new Diem(); diem.A = e.X; diem.B = e.Y; diem.Ten = thutu_diem.ToString(); diemColl.Add(diem); thutu_diem++; Invalidate(); return; // Dangve = false; } //Xóa điểm //Vẽ đường Diem kq = new Diem(); kq = KiemTraDiem_ThuocDiem(e.X, e.Y); if (kq != null) { if (DiemBatDau == "") { x1 = kq.A+5; y1 = kq.B+5; DiemBatDau = kq.Ten.ToString(); return; } if (DiemCuoi == "") { x2 = kq.A+5; y2 = kq.B+5; DiemCuoi = kq.Ten.ToString(); //Gán đừơng thẳng và đưa vào Coll DuongThang dt = new DuongThang(); Diem temp = new Diem(); temp.A = x1; temp.B = y1; temp.Ten = DiemBatDau; dt.DiemDau = temp; Diem temp1 = new Diem(); temp1.A = x2; temp1.B = y2; temp1.Ten = DiemCuoi; dt.DiemCuoi = temp1; int dodai =(int) Math.Sqrt(Math.Pow((dt.DiemDau.A - dt.DiemCuoi.A),2) + Math.Pow((dt.DiemDau.B - dt.DiemCuoi.B),2)); dt.ChieuDai = dodai; if(KiemTraDuongTonTai(dt)!=true &&DiemBatDau!=DiemCuoi) duongColl.Add(dt); //Nếu là đường vô hướng if (CoHuong == false) { dt = new DuongThang(); temp = new Diem(); temp1 = new Diem(); temp.A = x1; temp.B = y1; temp.Ten = DiemCuoi; dt.DiemDau = temp; temp1.A = x2; temp1.B = y2; temp1.Ten = DiemBatDau; dt.DiemCuoi = temp1; dodai = (int)Math.Sqrt(Math.Pow((dt.DiemDau.A - dt.DiemCuoi.A), 2) + Math.Pow((dt.DiemDau.B - dt.DiemCuoi.B), 2)); dt.ChieuDai = dodai; if (KiemTraDuongTonTai(dt) != true && DiemBatDau != DiemCuoi) duongColl.Add(dt); } Invalidate(); DiemBatDau = ""; DiemCuoi = ""; } } }
protected override void OnPaint(PaintEventArgs e) { ///////////////////////////////////////////vẽ tòan bộ////////////////////////// if (CachVe == 1) { //Vẽ đường foreach (DuongThang dt in duongColl) { VeDuong(dt.DiemDau, dt.DiemCuoi, Color.Green); } if (LoTrinh != null) { for (int i = 0; i < LoTrinh.Count - 1; i++) { foreach (DuongThang dt in duongColl) { if (dt.DiemDau.Ten == LoTrinh[i] && dt.DiemCuoi.Ten == LoTrinh[i + 1]) { VeDuong(dt.DiemDau, dt.DiemCuoi, Color.Red); break; } } } } //vẽ điểm foreach (Diem diem in diemColl) { VeDiem(diem.Ten, diem.A, diem.B, Color.Black); } if (LoTrinh != null) { for (int i = 0; i < LoTrinh.Count; i++) { foreach (Diem diem in diemColl) { if (diem.Ten == LoTrinh[i]) { VeDiem(diem.Ten, diem.A, diem.B, Color.Blue); break; } } } } } ///////////////////////////////////vẽ từng buớc/////////////////////////////// else if (CachVe == 2) { //Vẽ đường foreach (DuongThang dt in duongColl) { VeDuong(dt.DiemDau, dt.DiemCuoi, Color.Green); } Diem _dau = new Diem(); Diem _cuoi = new Diem(); Diem _trunggian = new Diem(); if (StepColl != null && StepColl.Count!=0 && Buoc!=0) { foreach (Diem diem in diemColl) { if (diem.Ten == StepColl.Index(Buoc - 1).Dau) { _dau.A = diem.A + 5; _dau.B = diem.B + 5; _dau.Ten = diem.Ten; } if (diem.Ten == StepColl.Index(Buoc - 1).TrungGian) { _trunggian.A = diem.A + 5; _trunggian.B = diem.B + 5; _trunggian.Ten = diem.Ten; } if (diem.Ten == StepColl.Index(Buoc - 1).Cuoi) { _cuoi.A = diem.A + 5; _cuoi.B = diem.B + 5; _cuoi.Ten = diem.Ten; } } foreach (DuongThang dt in duongColl) { if (dt.DiemDau.Ten == _dau.Ten && dt.DiemCuoi.Ten == _trunggian.Ten) { VeDuong(_dau, _trunggian, Color.Red); break; } else VeDuongAo(_dau, _trunggian, Color.Tomato); } foreach (DuongThang dt in duongColl) { if (dt.DiemDau.Ten == _trunggian.Ten && dt.DiemCuoi.Ten == _cuoi.Ten) { VeDuong(_trunggian, _cuoi, Color.Red); break; } else VeDuongAo(_trunggian, _cuoi, Color.Tomato); } } //vẽ điểm foreach (Diem diem in diemColl) { VeDiem(diem.Ten, diem.A, diem.B, Color.Black); } if (StepColl != null && StepColl.Count != 0&&Buoc!=0) { VeDiem(_trunggian.Ten,_trunggian.A-5, _trunggian.B-5, Color.Blue); } // CachVe = 2; return; } /////////////////////////////////vẽ bình thường//////////////////////////// else { //Vẽ đường foreach (DuongThang dt in duongColl) { VeDuong(dt.DiemDau, dt.DiemCuoi, Color.Green); } //vẽ điểm foreach (Diem diem in diemColl) { // VeDiem(diem.A, diem.B, Color.Red); VeDiem(diem.Ten, diem.A, diem.B, Color.Black); } } }
public DuongThang() { diemdau= null; diemcuoi=null; chieudai = 0; }
public void Add(Diem diem) { List.Add(diem); }