1. Trang chủ
  2. » Công Nghệ Thông Tin

CODE mô PHỎNG HIỂN THỊ mục TIÊU RADAR TRÊN màn HÌNH PC

51 562 5

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 51
Dung lượng 479 KB

Nội dung

t.Interval = 500; t.Tick += new EventHandlert_Tick; t.Enabled = true; backgroundWorker1.DoWork+=new System.ComponentModel.DoWorkEventHandlerbackgroundWorker1_DoWork; //update vi tri c

Trang 1

CODE MÔ PH NG HI N TH M C TIÊU RADAR TRÊN MÀN HÌNH PC ỎNG HIỂN THỊ MỤC TIÊU RADAR TRÊN MÀN HÌNH PC ỂN THỊ MỤC TIÊU RADAR TRÊN MÀN HÌNH PC Ị MỤC TIÊU RADAR TRÊN MÀN HÌNH PC ỤC TIÊU RADAR TRÊN MÀN HÌNH PCForm1

Coordinate td1 = new Coordinate(1,400, 400, 4000, 1000, "abc");

Coordinate td2 = new Coordinate(2, 200, 200, 4000, 1000, "abc");

List<Coordinate> qd1 = new List<Coordinate>();

System.Windows.Forms.Timer t = new System.Windows.Forms.Timer();

int speed = 400;

public static List<FlyingItem> listTarget = new List<FlyingItem>();

public static List<Rocket> listTenlua = new List<Rocket>();

Trang 2

t.Interval = 500;

t.Tick += new EventHandler(t_Tick);

t.Enabled = true;

backgroundWorker1.DoWork+=new System.ComponentModel.DoWorkEventHandler(backgroundWorker1_DoWork);

//update vi tri cac May bay trong khoang thoi gian = t.Interval

void t_Tick(object sender, EventArgs e)

// 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);

Trang 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

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,

Trang 4

_radar.ImageUpdate += new ImageUpdateHandler(_radar_ImageUpdate);

if (_radar._az + 20 > Radar.getAzimuth(current) && _radar._az - 20 < Radar.getAzimuth(current)

&& Radar.getRange(current) <= pictureBox1.Width / 2 && (Radar.getRange(item._current) * Math.Sin(max_angle)) > item._current.Z)

{

Trang 5

bool Flag = true;

for (int j = 0; j < lvTarget.Items.Count; j++)

Trang 6

System.Media.SoundPlayer myPlayer = new System.Media.SoundPlayer(); myPlayer.SoundLocation = @"c:\sound.wav";

Rocket item= listTenlua[m];

//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

Trang 7

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 <listTarget.Count; i++)

Trang 8

}

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) <= pictureBox1.Width / 2 && (Radar.getRange(item._current) * Math.Sin(max_angle)) > 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());

Trang 9

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();

Trang 10

_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 == "")

Trang 14

//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<Coordinate> qd= new List<Coordinate>();

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");

//may bay 3 - quan su(ta)

toado1 = new Coordinate(1, 494, 115, 12, 2000, "abc");

Trang 15

toado2 = new Coordinate(2, 352, 428, 12, 2000, "abc");

toado1 = new Coordinate(1, 227, 79, 14, 2000, "abc");

toado2 = new Coordinate(2, 436, 483, 14, 2000, "abc");

toado1 = new Coordinate(1, 58, 242, 6, 1200, "abc");

toado2 = new Coordinate(2, 512, 372, 6, 1200, "abc");

Trang 16

{

_radar.numberOfSpirals = Convert.ToInt32(txtNoSpiral.Text); _radar.CreateBaseImageSpiralSweep(pXoanOc.Width);

Trang 17

private void txtAzimuth_TextChanged(object sender, EventArgs e)

Trang 18

public Coordinate _current;

public Coordinate _to;

public string _category;

public int ID;

public List<Coordinate> airline= new List<Coordinate>();

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";

// 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);

Trang 19

//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);

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);

Trang 20

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;

Trang 21

float fAngle, fScale;

fAngle = (float)(d * 2 * Math.PI / (iNumPoints / iNumRevs));

fScale = 1 - (float)d / iNumPoints;

pt.X = (float)((size / 2) * (1 + fScale * Math.Sin(fAngle)));

pt.Y = (float)((size / 2) * (1 + fScale * Math.Cos(fAngle)));

g.FillRectangle(new SolidBrush(_color), new RectangleF(pt, new SizeF((float)8, (float)8))); }

// rotate coords 90deg W = 180deg trig

double angle = (270d + (double)azimuth);

// turn into radians

Trang 22

Color _topColor = Color.FromArgb(0, 120, 0);

Color _bottomColor = Color.FromArgb(0, 40, 0);

Color _lineColor = Color.FromArgb(0, 255, 0);

Color _targetColor = Color.FromArgb(255, 0, 0);

private void CreateTarget_Load(object sender, EventArgs e)

Trang 23

Graphics g = Graphics.FromImage(i);

Pen p = new Pen(_lineColor);

// lam cho anh dep hon

g.CompositingQuality = CompositingQuality.HighQuality;

g.InterpolationMode = InterpolationMode.Bicubic;

g.SmoothingMode = SmoothingMode.AntiAlias;

g.TextRenderingHint = TextRenderingHint.AntiAlias;

// draw the background of the radar

g.FillEllipse(new LinearGradientBrush(new Point((int)(_size / 2), 0), new Point((int)(_size / 2), _size

- 1), _topColor, _bottomColor), 0, 0, _size - 1, _size - 1);

// draw the outer ring (0° elevation)

g.DrawEllipse(p, 0, 0, _size - 1, _size - 1);

// draw the inner ring (60° elevation)

int interval = _size / 5;

for (int j = 1; j < 5; j++)

{

int interval1 = interval * j;

g.DrawEllipse(p, (_size - interval1) / 2, (_size - interval1) / 2, interval1, interval1);

Font ab = new Font("Arial", 10);

g.DrawString((30 - 6 * j).ToString() + "0", ab, Brushes.Red, interval1 / 2, _size / 2);

g.DrawString((30 - 6 * j).ToString() + "0", ab, Brushes.Red, _size - interval1 / 2 - 15, _size / 2); }

// draw the x and y axis lines

g.DrawLine(p, new Point(0, (int)(_size / 2)), new Point(_size - 1, (int)(_size / 2)));

g.DrawLine(p, new Point((int)(_size / 2), 0), new Point((int)(_size / 2), _size - 1));

Font abc = new Font("Arial", 10);

g.DrawString("W", abc, Brushes.Red, 0, _size / 2);

g.DrawString("N", abc, Brushes.Red, _size / 2, 0);

g.DrawString("E", abc, Brushes.Red, _size - 15, _size / 2);

g.DrawString("S", abc, Brushes.Red, _size / 2, _size - 15);

// release the graphics object

Trang 24

{

txtToado.Text = e.X.ToString() + "," + e.Y.ToString();

PointF pt1= new PointF(e.X,e.Y);

Graphics g = Graphics.FromImage(pictureBox1.Image);

Color _lineColor = Color.FromArgb(255, 255, 0);

Pen p = new Pen(_lineColor);

g.DrawRectangle(p, e.X, e.Y, 10, 10);

if (lvAirline.Items.Count == 0)

{ }

else

{

ListViewItem item = lvAirline.Items[lvAirline.Items.Count-1];

string[] chuoi = item.SubItems[1].Text.Split(',');

PointF pt2 = new PointF((float)Convert.ToDouble(chuoi[0].ToString()), (float)Convert.ToDouble(chuoi[1].ToString()));

Trang 25

Color color = colorDialog1.Color;

List<Coordinate> qd = new List<Coordinate>();

Ngày đăng: 03/12/2015, 23:21

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

w