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<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>();
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 <= 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
{
}
}
_radar.AddItem(item);
_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)
{
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) <= 60)
{