YOMEDIA
ADSENSE
CODE MÔ PHỎNG HIỂN THỊ MỤC TIÊU RADAR TRÊN MÀN HÌNH PC
328
lượt xem 72
download
lượt xem 72
download
Download
Vui lòng tải xuống để xem tài liệu đầy đủ
TÀI LIỆU THAM KHẢO CODE MÔ PHỎNG HIỂN THỊ MỤC TIÊU RADAR TRÊN MÀN HÌNH PC using System; using System.Collections; using System.Collections.Generic; using System.Drawing; using System.Drawing.Design; using System.Drawing.Drawing2D; using System.Drawing.Imaging; using System.Drawing.Text; using System.Windows.Forms; using System.Threading; using System.ComponentModel; using System.Windows;
AMBIENT/
Chủ đề:
Bình luận(0) Đăng nhập để gửi bình luận!
Nội dung Text: CODE MÔ PHỎNG HIỂN THỊ MỤC TIÊU RADAR TRÊN MÀN HÌNH PC
- CODE MÔ PHỎNG HIỂN THỊ MỤC TIÊU RADAR TRÊN MÀN HÌNH PC Form1 using System; using System.Collections; using System.Collections.Generic; using System.Drawing; using System.Drawing.Design; using System.Drawing.Drawing2D; using System.Drawing.Imaging; using System.Drawing.Text; using System.Windows.Forms; using System.Threading; using System.ComponentModel; using System.Windows; namespace Radar { public partial class MainForm : Form { Radar _radar; Coordinate td1 = new Coordinate(1,400, 400, 4000, 1000, "abc"); Coordinate td2 = new Coordinate(2, 200, 200, 4000, 1000, "abc"); List qd1 = new List(); System.Windows.Forms.Timer t = new System.Windows.Forms.Timer(); int speed = 400; public static List listTarget = new List(); public static List listTenlua = new List(); public MainForm() { InitializeComponent(); // internal item update timer
- t.Interval = 500; t.Tick += new EventHandler(t_Tick); t.Enabled = true; backgroundWorker1.DoWork+=new System.ComponentModel.DoWorkEventHandler(backgroundWorker1_DoWork); } void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { System.Media.SoundPlayer myPlayer = new System.Media.SoundPlayer(); myPlayer.SoundLocation = @"c:\sound1.wav"; myPlayer.Play(); } //update vi tri cac May bay trong khoang thoi gian = t.Interval void t_Tick(object sender, EventArgs e) { double max_angle = _radar.maxAngle * 0.0174532925d; if (listTarget.Count == 0) { lvTarget.Items.Clear(); cbTarget.Items.Clear(); cbTarget.Text = ""; } else { //lvTarget.Items.Clear(); cbTarget.Items.Clear(); // select which of the three items to update foreach (FlyingItem item in listTarget) { //khoang cach di duoc cua muc tieu trong 1 s double s = item._current.velocity * 1000 / (3600000 * 3);
- //toa do tuong doi giua diem di va diem den double x = item._to.X - item._current.X; double y = item._to.Y - item._current.Y; double chenhlech_kc = Math.Sqrt(x * x + y * y); double gocngang = Math.Acos(x / chenhlech_kc); //doi sang do. gocngang = gocngang / 0.0174532925d; if (y < 0) { gocngang = 360d - gocngang; } //doi sang radian de tinh sin va cos gocngang *= 0.0174532925d; double z = item._to.Z - item._current.Z; double gocdung = Math.Asin(z / Math.Sqrt(z * z + chenhlech_kc * chenhlech_kc)); //toa do muc tieu sau 1s double z1 = item._current.Z + (s * Math.Sin(gocdung)); double chenhlech_kc1 = (float)(s * Math.Abs(Math.Cos(gocdung))); double x1 = item._current.X + chenhlech_kc1 * Math.Cos(gocngang); double y1 = item._current.Y + chenhlech_kc1 * Math.Sin(gocngang); Coordinate current = new Coordinate(item._current.stt, x1, y1, z1, item._current.velocity, "abc"); //gan diem nay thanh diem bat dau item._current = current; if (z >= 0) { item._current = current; if (z1 >= item._to.Z) { for (int k = 0; k < item.airline.Count; k++) { Coordinate td = item.airline[k]; if (td1.stt == item._to.stt) item._to = item.airline[k + 1];
- else {} } } else { } } else { item._current = current; if (z1 Radar.getAzimuth(current) && _radar._az - 20 < Radar.getAzimuth(current) && Radar.getRange(current) item._current.Z) {
- bool Flag = true; for (int j = 0; j < lvTarget.Items.Count; j++) { if (lvTarget.Items[j].Text.Trim() == item.ID.ToString().Trim()) { ListViewItem lvItem = lvTarget.Items[j]; lvItem.Text = item.ID.ToString(); lvItem.SubItems[1].Text = (item._category); lvItem.SubItems[2].Text = (Radar.getAzimuth(item._current).ToString()); int rg = (int)Radar.getRange(item._current); lvItem.SubItems[3].Text = (rg.ToString()); lvItem.SubItems[4].Text = (item._current.Z.ToString()); lvItem.SubItems[5].Text = (item._current.velocity.ToString()); Flag = false; } } if (Flag) { ListViewItem lvItem = new ListViewItem(); lvItem.Text = item.ID.ToString(); lvItem.SubItems.Add(item._category); lvItem.SubItems.Add(Radar.getAzimuth(item._current).ToString()); int rg = (int)Radar.getRange(item._current); lvItem.SubItems.Add(rg.ToString()); lvItem.SubItems.Add(item._current.Z.ToString()); lvItem.SubItems.Add(item._current.velocity.ToString()); lvItem.BackColor = item._color; lvTarget.Items.Add(lvItem); } if (Radar.getRange(current)
- System.Media.SoundPlayer myPlayer = new System.Media.SoundPlayer(); myPlayer.SoundLocation = @"c:\sound.wav"; myPlayer.Play(); } } cbTarget.Items.Add(item.ID); } } if (listTenlua.Count==0) {} else { //lvTarget.Items.Clear(); //cbTarget.Items.Clear(); // select which of the three items to update for(int m=0;m
- double z = item._to.Z - item._current.Z; double gocdung = Math.Asin(z /Math.Sqrt(z*z+chenhlech_kc*chenhlech_kc)); //toa do muc tieu sau 1s double z1 = item._current.Z+(s*Math.Sin(gocdung)); double chenhlech_kc1 = (float)(s *Math.Abs( Math.Cos(gocdung))); double x1 = item._current.X + chenhlech_kc1 * Math.Cos(gocngang); double y1 = item._current.Y + chenhlech_kc1 * Math.Sin(gocngang); Coordinate current = new Coordinate(item._current.stt,x1, y1, z1, item._current.velocity, "abc"); //gan diem nay thanh diem bat dau item._current = current; //tim vi tri hien tai cua muc tieu for (int i = 0; i
- } if(lvTarget.Items[n].Text==item.ID.ToString()) lvTarget.Items.Remove(lvTarget.Items[n]); } listTenlua.Remove(item); listTarget.Remove(mb); backgroundWorker1.RunWorkerAsync(); MessageBox.Show("Mục tiêu đã bị tiêu diệt"); } else { item._to = mb._current; _radar.AddItem(item); if (_radar._az + 20 > Radar.getAzimuth(current) && _radar._az - 20 < Radar.getAzimuth(current) && Radar.getRange(current) item._current.Z) { bool Flag = true; for (int j = 0; j < lvTarget.Items.Count; j++) { if (lvTarget.Items[j].Text.Trim() == item.ID.ToString().Trim()) //lvTarget.Items.Remove(lvTarget.Items[j]); { ListViewItem lvItem = lvTarget.Items[j]; lvItem.Text = item.ID.ToString(); lvItem.SubItems[1].Text = (item._category); lvItem.SubItems[2].Text = (Radar.getAzimuth(item._current).ToString());
- double rg = Radar.getRange(item._current); lvItem.SubItems[3].Text = (rg.ToString()); lvItem.SubItems[4].Text = (item._current.Z.ToString()); lvItem.SubItems[5].Text = (item._current.velocity.ToString()); Flag = false; } } if (Flag) { ListViewItem lvItem = new ListViewItem(); lvItem.Text = item.ID.ToString(); lvItem.SubItems.Add(item._category); lvItem.SubItems.Add(Radar.getAzimuth(item._current).ToString()); double rg = Radar.getRange(item._current); lvItem.SubItems.Add(rg.ToString()); lvItem.SubItems.Add(item._current.Z.ToString()); lvItem.SubItems.Add(item._current.velocity.ToString()); lvItem.BackColor = item._color; lvTarget.Items.Add(lvItem); } } } } } } } } private void Form1_Load(object sender, EventArgs e) { _radar = new Radar(pictureBox1.Width,pQuetThang.Width,pQuetThang.Height,pQuetVong.Width); _radar.numberOfSpirals = 3; pictureBox1.Image = _radar.Image; _radar.ImageUpdate += new ImageUpdateHandler(_radar_ImageUpdate); _radar.DrawScanInterval = speed; txtMaxAngle.Text = _radar.maxAngle.ToString();
- trackBarSpeed.Maximum = 20; trackBarSpeed.TickFrequency = 1; pQuetThang.Image = _radar.outputImageStraightSweep; pQuetVong.Image = _radar.outputImageCircleSweep; pXoanOc.Image = _radar.outputImageSpiralSweep; } void _radar_ImageUpdate(object sender, ImageUpdateEventArgs e) { // this event is important to catch! pictureBox1.Image = e.Image; pQuetThang.Image = _radar.outputImageStraightSweep; pQuetVong.Image = _radar.outputImageCircleSweep; pXoanOc.Image = _radar.outputImageSpiralSweep; txtAzimuth.Text = _radar._az.ToString(); } private void trackBarSpeed_Scroll(object sender, EventArgs e) { if (trackBarSpeed.Value == 0) trackBarSpeed.Value = 1; _radar.DrawScanInterval = (speed )/trackBarSpeed.Value ; _radar.ImageUpdate += new ImageUpdateHandler(_radar_ImageUpdate); } private void rbThuan_CheckedChanged(object sender, EventArgs e) { if (rbThuan.Checked) _radar.clockwiseScan = true; _radar.ImageUpdate += new ImageUpdateHandler(_radar_ImageUpdate); } private void rbNguoc_CheckedChanged(object sender, EventArgs e) { if (rbNguoc.Checked) _radar.clockwiseScan = false; _radar.ImageUpdate += new ImageUpdateHandler(_radar_ImageUpdate); } private void cbTarget_TextChanged(object sender, EventArgs e) { if (cbTarget.Text == "")
- { _radar.targetCatched = 0; } else { if (_radar.targetCatched == 0) {} else _radar.changeTargetFlag = true; int id = Convert.ToInt16(cbTarget.Text); _radar.targetCatched = id; } } private void button1_Click(object sender, EventArgs e) { CreateTarget mt = new CreateTarget(); mt.Show(); } private void btTieudiet_Click(object sender, EventArgs e) { if (cbTarget.Text == "") { return; } Rocket tenlua1 = new Rocket(Convert.ToInt16(cbTarget.Text)); listTenlua.Add(tenlua1); } private void btSwitch_Click(object sender, EventArgs e) { if (rbThang.Checked) { pQuetThang.Visible = true; pQuetVong.Visible = false; pXoanOc.Visible = false; } else if (rbTron.Checked) {
- pQuetThang.Visible = false; pQuetVong.Visible = true; pXoanOc.Visible = false; } else if (rbXoanOc.Checked) { pQuetThang.Visible = false; pQuetVong.Visible = false; pXoanOc.Visible = true; } } private void rbThang_CheckedChanged(object sender, EventArgs e) { if (rbThang.Checked) { pQuetThang.Visible = true; pQuetVong.Visible = false; pXoanOc.Visible = false; txtNoSpiral.Visible = false; label4.Visible = false; } else if (rbTron.Checked) { pQuetThang.Visible = false; pQuetVong.Visible = true; pXoanOc.Visible = false; txtNoSpiral.Visible = false; label4.Visible = false; } else if (rbXoanOc.Checked) { pQuetThang.Visible = false; pQuetVong.Visible = false; pXoanOc.Visible = true; txtNoSpiral.Visible = true; label4.Visible = true; }
- } private void rbTron_CheckedChanged(object sender, EventArgs e) { if (rbThang.Checked) { pQuetThang.Visible = true; pQuetVong.Visible = false; pXoanOc.Visible = false; txtNoSpiral.Visible = false; label4.Visible = false; } else if (rbTron.Checked) { pQuetThang.Visible = false; pQuetVong.Visible = true; pXoanOc.Visible = false; txtNoSpiral.Visible = false; label4.Visible = false; } else if (rbXoanOc.Checked) { pQuetThang.Visible = false; pQuetVong.Visible = false; pXoanOc.Visible = true; txtNoSpiral.Visible = true; label4.Visible = true; } } private void rbXoanOc_CheckedChanged(object sender, EventArgs e) { if (rbThang.Checked) { pQuetThang.Visible = true; pQuetVong.Visible = false; pXoanOc.Visible = false; txtNoSpiral.Visible = false; label4.Visible = false;
- } else if (rbTron.Checked) { pQuetThang.Visible = false; pQuetVong.Visible = true; pXoanOc.Visible = false; txtNoSpiral.Visible = false; label4.Visible = false; } else if (rbXoanOc.Checked) { pQuetThang.Visible = false; pQuetVong.Visible = false; pXoanOc.Visible = true; txtNoSpiral.Visible = true; label4.Visible = true; } } private void button2_Click(object sender, EventArgs e) { //may bay 1- dan su - mau do Coordinate toado1 = new Coordinate(1, 439, 451, 10, 1000, "abc"); Coordinate toado2 = new Coordinate(2, 101,377, 10, 1000, "abc"); List qd= new List(); qd.Add(toado1); qd.Add(toado2); FlyingItem mb = new FlyingItem("Dân sự", 1, qd, Color.Red); MainForm.listTarget.Add(mb); //may bay 2- dan su- da troi toado1 = new Coordinate(1, 239, 480, 8, 800, "abc"); toado2 = new Coordinate(2, 440, 157, 8, 800, "abc"); qd = new List(); qd.Add(toado1); qd.Add(toado2); mb = new FlyingItem("Dân sự", 2, qd, Color.Blue); MainForm.listTarget.Add(mb); //may bay 3 - quan su(ta) toado1 = new Coordinate(1, 494, 115, 12, 2000, "abc");
- toado2 = new Coordinate(2, 352, 428, 12, 2000, "abc"); qd = new List(); qd.Add(toado1); qd.Add(toado2); mb = new FlyingItem("Quân sự (ta)", 3, qd, Color.Yellow); MainForm.listTarget.Add(mb); //may bay 4 toado1 = new Coordinate(1, 227, 79, 14, 2000, "abc"); toado2 = new Coordinate(2, 436, 483, 14, 2000, "abc"); qd = new List(); qd.Add(toado1); qd.Add(toado2); mb = new FlyingItem("Quân sự (địch)", 4, qd, Color.Purple); MainForm.listTarget.Add(mb); //may bay 5 toado1 = new Coordinate(1, 58, 242, 6, 1200, "abc"); toado2 = new Coordinate(2, 512, 372, 6, 1200, "abc"); qd = new List(); qd.Add(toado1); qd.Add(toado2); mb = new FlyingItem("Quân sự (địch)", 5, qd, Color.Gray); MainForm.listTarget.Add(mb); //may bay 6 toado1 = new Coordinate(1, 527, 197, 12, 1500, "abc"); toado2 = new Coordinate(2, 390, 419, 12, 1500, "abc"); qd = new List(); qd.Add(toado1); qd.Add(toado2); mb = new FlyingItem("Quân sự (ta)", 6, qd, Color.Pink); MainForm.listTarget.Add(mb); } private void textBox1_TextChanged(object sender, EventArgs e) { try { if (txtNoSpiral.Text == "") {} else
- { _radar.numberOfSpirals = Convert.ToInt32(txtNoSpiral.Text); _radar.CreateBaseImageSpiralSweep(pXoanOc.Width); pXoanOc.Image = _radar.outputImageSpiralSweep; } } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void txtMaxAngle_LostFocus(object sender, EventArgs e) { try { double max_angle = Convert.ToDouble(txtMaxAngle.Text); if (max_angle 60) { MessageBox.Show("Góc nâng của radar không đúng"); return; } else _radar.maxAngle = max_angle; } catch { MessageBox.Show("Góc nâng của radar không đúng"); return; } } private void cbTarget_SelectedIndexChanged(object sender, EventArgs e) { }
- private void txtAzimuth_TextChanged(object sender, EventArgs e) { } private void txtMaxAngle_TextChanged(object sender, EventArgs e) { } private void lvTarget_SelectedIndexChanged(object sender, EventArgs e) { } private void pictureBox1_Click(object sender, EventArgs e) { } private void label1_Click(object sender, EventArgs e) { } private void label4_Click(object sender, EventArgs e) { } } } May Bay
- using System; using System.Collections.Generic; using System.Text; using System.Drawing; using System.Drawing.Drawing2D; namespace Radar { public class FlyingItem { public Coordinate _current; public Coordinate _to; public string _category; public int ID; public List airline= new List(); public Color _color; public FlyingItem() {} public FlyingItem(int targetID) { _current = new Coordinate(0, 300, 300, 0, 4000, "abc"); _to = new Coordinate(1, 600, 600, 0, 0, "abc"); _category = "Tên lửa"; ID = 1000; } public FlyingItem(string loai, int id,List qd,Color color) { ID = id; _category = loai; airline = qd; _current = qd[0]; _to = qd[1]; _color = color; } // ve cac muc tieu tren man hinh scan cua radar public void DrawItem(Radar radar, Graphics g) { PointF cp = new PointF((float)_current.X, (float)_current.Y);
- //loai 1 - Hinh vuong - Quan ta if (_category =="Quân sự (ta)") { //PointF cp = radar.AzRg2XY(_azimuth, _range); //cp = this.From; PointF topLeft = new PointF(cp.X - ((float)8 / 2), cp.Y - ((float)8 / 2)); g.FillRectangle(new SolidBrush(_color), new RectangleF(topLeft, new SizeF((float)8, (float)8))); } //loai 2 - Hinh tron - Dan su else if (_category == "Dân sự") { //PointF cp = radar.AzRg2XY(_azimuth, _range); PointF topLeft = new PointF(cp.X - ((float)8 / 2), cp.Y - ((float)8 / 2)); g.FillEllipse(new SolidBrush(_color), new RectangleF(topLeft, new SizeF((float)8, (float)8))); } //loai 3 - Hinh tam giac - Quan dich else if (_category == "Quân sự (địch)") { //PointF cp = radar.AzRg2XY(_azimuth, _range); PointF _topLeft = new PointF(cp.X - ((float)8 / 2), cp.Y - ((float)8 / 2)); PointF p1 = new PointF(((float)_topLeft.X + ((float)8 / 2F)), (float)_topLeft.Y); PointF p2 = new PointF((float)_topLeft.X, (float)_topLeft.Y + (float)8); PointF p3 = new PointF((float)_topLeft.X + (float)8, (float)_topLeft.Y + (float)8); GraphicsPath _gp = new GraphicsPath(FillMode.Winding); _gp.AddPolygon(new PointF[] { p1, p2, p3 }); g.FillPath(new SolidBrush(_color), _gp); } //loai 4 _ Hinh tam giac vang - Ten lua else { PointF _topLeft = new PointF(cp.X - ((float)8 / 2), cp.Y - ((float)8 / 2)); PointF p1 = new PointF(((float)_topLeft.X + ((float)8 / 2F)), (float)_topLeft.Y); PointF p2 = new PointF((float)_topLeft.X, (float)_topLeft.Y + (float)8);
- PointF p3 = new PointF((float)_topLeft.X + (float)8, (float)_topLeft.Y + (float)8); GraphicsPath _gp = new GraphicsPath(FillMode.Winding); _gp.AddPolygon(new PointF[] { p1, p2, p3 }); g.FillPath(new SolidBrush(Color.Yellow), _gp); } } // ve cac muc tieu tren man hinh quet thang public void DrawItemStraightSweep(Radar radar,Graphics g,int w,int h) { double d = Radar.getRange(_current); PointF pt1 = new PointF((float)d * w / 300, (float)h / 4); g.FillRectangle(new SolidBrush(_color), new RectangleF(pt1, new SizeF((float)8, (float)8))); PointF pt2 = new PointF((float)(d%100) * w/ 100, (float)h / 2); g.FillRectangle(new SolidBrush(_color), new RectangleF(pt2, new SizeF((float)8, (float)8))); PointF pt3 = new PointF((float)(d%10) * w / 10, (float)h*3 / 4); g.FillRectangle(new SolidBrush(_color), new RectangleF(pt3, new SizeF((float)8, (float)8))); } // ve cac muc tieu tren man hinh quet tron public void DrawItemCircleSweep(Radar radar, Graphics g, int size) { double d = Radar.getRange(_current); PointF pt1 = AzRg2XY((float)(d) * 360 / 300, size / 2, size+40); g.FillRectangle(new SolidBrush(_color), new RectangleF(pt1, new SizeF((float)8, (float)8))); PointF pt2 = AzRg2XY((float)(d % 100) * 360 / 100, size / 3, size + 40); g.FillRectangle(new SolidBrush(_color), new RectangleF(pt2, new SizeF((float)8, (float)8))); PointF pt3 = AzRg2XY((float)(d % 10) * 360 / 10, size / 6, size + 40); g.FillRectangle(new SolidBrush(_color), new RectangleF(pt3, new SizeF((float)8, (float)8))); } // ve cac muc tieu tren man quet xoan oc public void DrawItemSpiralSweep(Radar radar, Graphics g, int size,int numRev) { double d = 300-Radar.getRange(_current); PointF pt = new PointF(); int iNumRevs = numRev; int iNumPoints = 300;
Thêm tài liệu vào bộ sưu tập có sẵn:
Báo xấu
LAVA
AANETWORK
TRỢ GIÚP
HỖ TRỢ KHÁCH HÀNG
Chịu trách nhiệm nội dung:
Nguyễn Công Hà - Giám đốc Công ty TNHH TÀI LIỆU TRỰC TUYẾN VI NA
LIÊN HỆ
Địa chỉ: P402, 54A Nơ Trang Long, Phường 14, Q.Bình Thạnh, TP.HCM
Hotline: 093 303 0098
Email: support@tailieu.vn