Bao Cao Radar

57
Trường Đại Học Bách Khoa Hà Nội Khoa Điện tử - Viễn thông Báo cáo bài tập lớn môn định vị và dẫn đường Đề tài: Mô phỏng hiển thị màn hình mục tiêu RADAR trên máy tính Giáo viên hướng dẫn: Thầy Hà Duyên Trung Nhóm sinh viên thực hiện: Hà Văn Nam - ĐT3 - K52 20072003 Nguyễn Văn Biên - ĐT3 - K52 20070210 1

Transcript of Bao Cao Radar

Page 1: Bao Cao Radar

Trường Đại Học Bách Khoa Hà Nội

Khoa Điện tử - Viễn thông

Báo cáo bài tập lớn

môn định vị và dẫn đường

Đề tài:

Mô phỏng hiển thị màn hình mục tiêu

RADAR trên máy tính

Giáo viên hướng dẫn: Thầy Hà Duyên Trung

Nhóm sinh viên thực hiện:

Hà Văn Nam - ĐT3 - K52 20072003

Nguyễn Văn Biên - ĐT3 - K52 20070210

Phạm Minh Tuấn - ĐT3 - K52 20070316

Trần Ngọc Thuần - ĐT3 - K52 20072785

Đặng Đức Tôn - ĐT3 - K52 20072970

1

Page 2: Bao Cao Radar

Mục LụcLời nói đầu....................................................................................................................................................3

I. GIỚI THIỆU CHUNG:........................................................................................................................5

1. Những vấn đề chung về Radar.........................................................................................................5

2. Nguyên tắc nhận tin tức Radar........................................................................................................6

3. Sơ đồ nguyên lý của radar:...............................................................................................................7

4. Tính năng kỹ thuật của Radar:........................................................................................................8

5. Nguyên lý đo khoảng cách, vận tốc của mục tiêu:..........................................................................9

II. PHẦN MỀM MÔ PHỎNG:..............................................................................................................12

1. Yêu cầu của đề bài:.........................................................................................................................12

2. Thuật toán mô phỏng:....................................................................................................................13

3. Viết chương trình sử dụng Visual Studio 2008 – ngôn ngữ C#:..................................................13

Mã nguồn chương trình mô phỏng Radar:...............................................................................................14

a.Program.cs........................................................................................................................................14

b.Radar.cs............................................................................................................................................14

c.RadarItem.cs.....................................................................................................................................23

d.Typescan.cs......................................................................................................................................32

4.Kết quả thu được:..................................................................................................................................43

5.Kết luận, nhận xét và đánh giá:.............................................................................................................47

2

Page 3: Bao Cao Radar

Lời nói đầu

Radar là tiếng viết tắt của tiếng Anh “Radio Dectection and Ranging” có

nghĩa là phương tiện dùng sóng vô tuyến điện để phát hiện và xác định vị trí mục

tiêu. Tên này do Hải quân Mỹ đặt ra trong đại chiến thứ hai.

Radar là một trong những thành tựu khoa học kỹ thuật tiên tiến và được áp

dụng rộng rãi trong thời đại ngày nay. Trong các loại vũ khí công nghệ cao thì Ra-

3

Page 4: Bao Cao Radar

dar có nhiều ứng dụng đặc biệt. Radar có khả năng phát hiện ra mục tiêu ở cự ly rất

xa trong bất kỳ điều kiện nào, tính toán được tốc độ, hướng bay và các đặc điểm

của mục tiêu để chỉ thị cho các đơn vị hỏa lực có thể bám sát và tiêu diệt mục tiêu.

Sau chiến tranh, kỹ thuật tên lửa và vũ khí tiến công hàng không ngày càng phát

triển thì vai trờ của Radar ngày càng trở nên quan trọng. Radar phòng không là lực

lượng đảm bảo chủ yếu tin tức về máy bay địch trong đội hình chiến đấu của quân

chủng – phòng không có mặt trên khắp các chiến trường, phục vụ các chiến dịch.

Trong các lĩnh vực kĩ thuật hàng không, hàng hải, vũ trụ…radar cũng đóng

vai trò không thể thiếu. Nhờ Radar mà việc diều khiển các con tàu vũ trụ thật dễ

dàng và chính xác. Trong lĩnh vực khí tượng thủy văn, Radar giúp cho việc dự báo

thời tiết được chính xác và thuận lợi. Radar có thể phát hiện được sự bất thường

của khí quyển xa hàng trăm Km, giúp máy bay, tàu bè có thể phòng tránh an toàn

nên trong hàng hải, Radar đóng vai trò như “hoa tiêu số” giúp tàu thuyền đi lại an

toàn, tránh được sự va chạm với các tàu bè khác cũng như đâm vào các núi băng

trôi. Còn trong hàng không, nhờ có Radar mà máy bay có thể hạ cánh và cất cánh

trong bất kỳ trường hợp thời tiết nào.

Radar được ứng dụng rất nhiều ngành kỹ thuật và đời sống. Do vậy việc

nghiên cứu, phát triển Radar đều được các nước trên thế giới quan tâm chú trọng.

Trong bài tập này, chúng em làm mô phỏng màn hình hiển thị của hệ thống

Radar và các phương pháp hiển thị mục tiêu. Do hạn chế về mặt kiến thức và thời

gian nên chương trình mô phỏng còn nhiều thiếu sót, em mong thầy giáo và các

bạn đóng góp ý kiến để chương trình của nhóm em được hoàn thiện hơn.

4

Page 5: Bao Cao Radar

I. GIỚI THIỆU CHUNG:1. Những vấn đề chung về Radar

- Radar là thiết bị đảm bảo nhận những tin tức về những mục tiêu nhờ thu

và phân tích sóng vô tuyến.

- Mục tiêu có thể là:

Loại khí động lực: máy bay, tên lửa có cánh…

Loại vượt đại châu và vũ trụ: đầu đạn hạt nhân, vệ tinh…

Mục tiêu trên mặt đất, trên mặt nước và mục tiêu có nguồn gốc

thiên nhiên.

- Quá trình nhận biết tin tức Radar trong nhiều trường hợp có thể chia

thành các bước sau:

Phát hiện mục tiêu: là quyết đoán có hay không có mục tiêu trong

một vùng không gian với xác suất quyết đoán sai nào đó cho phép.

Đo tọa độ và các tham số chuyển động với một sai số cho phép nào

đó.

Phân biệt là bái toán phát hiện và đo đạc các tham số của mục tiêu

khi gần mục tiêu này còn có những mục tiêu khác.

Nhận biết: đài Radar sẽ xác định mục tiêu thuộc loại nào, của ai,

bay đi đâu, trên đường bay nào do đó trên mục tiêu phải gắn tran-

sponder. Bước này chỉ có ở Radar thứ cấp.

- Các thiết bị Radar phải có khả năng chống nhiễu cao đối với nhiễu thiên

nhiên và nhiễu nhân tạo. Khả năng chống nhiễu là khả năng của đài Ra-

dar đảm bảo được các chỉ tiêu chất lượng, phát hiện, đo lường ở một mức

5

Page 6: Bao Cao Radar

độ đã cho khi có nhiễu, đó cũng chính là khả năng sử dụng nguồn nhiễu

làm tin tức Radar.

- Sóng Radar có thể là sóng siêu âm dùng để phát hiện mục tiêu dưới nước.

Thông thường sóng Radar là sóng điện từ có bước sóng từ 1mm đến

100km. Các sóng ở dải mm, cm, m có vai trò quan trọng nhất.Hiện nay

các sóng điện từ ngắn hơn như sóng hồng ngoại, sóng ánh sáng cũng

được sử dụng trong Radar.

2. Nguyên tắc nhận tin tức Radar

- Những tin tức về mục tiêu mang trong tín hiệu Radar là những dao động

điện từ có các tham số liên hệ chặt chẽ với các tham số của mục tiêu.

- Phương pháp nhận tin tửc Radar thông thường nhất là phương pháp Ra-

dar chủ động. Radar này chiếu xạ mục tiêu nhờ năng lượng điện tử và

sóng phản xạ bởi mục tiêu bằng thiết bị thu. Phản xạ sóng xảy ra ở giới

hạn hai môi trường có các tính chất điện từ và từ khác nhau. Chú ý những

dao động điện từ chiếu xạ mục tiêu vẫn chưa phải là tín hiệu Radar vì

chúng không chứa đựng những tin tức về mục tiêu

- Khi cần nhận biết mục tiêu, tín hiệu Radar được tạo nên bằng phương

pháp hỏi đáp chủ động. Trong trường hợp này năng lượng điện từ chiếu

xạ mục tiêu làm cho máy trả lời trên mục tiêu phát ra những tín hiệu vô

tuyến hoàn toàn xác định, những tín hiệu này được nhận bởi máy thu của

đài Radar.

- Khi phát hiện và đo lường các tham số của mục tiêu chúng ta sử dụng

những tính chất vật lý của sóng vô tuyến:

Sóng điện từ trong môi trường đồng nhất và đăng hướng thì truyền

thẳng.

6

Page 7: Bao Cao Radar

Sóng điện từ truyền với tốc độ trung bình bằng vận tốc ánh sang

trong môi truờng khí quyển và trong chân không.

Khi sóng điện từ truyền lan trên môi trường đồng nhất nếu gặp

phải môi trường thứ hai không đồng nhất với môi trường thứ nhất

(không cùng chiết suất) thì xảy ra hiện tượng tán xạ sóng điện từ.

Hiện tượng tán xạ xảy ra ở xung quanh môi trường thứ hai hay ở

biên giới giữa hai môi trường, chỉ có một phần phản xạ về nguồn

phát xạ. Tia này cùng phương ngược chiều với tia chiếu xạ giúp

cho hệ thống phát hiện được mục tiêu, là đối tượng hay mục tiêu

cần định vị.

3. Sơ đồ nguyên lý của radar :

Máy phát tạo ra 1 xung điện cao tần, qua chuyển mạch tới ăng ten và

bức xạ vào không gian. Xung radio gặp mục tiêu phản xạ lại, qua ăng ten

vào máy thu, qua bộ khuếch đại và bộ sửa đổi tín hiệu cho ta tín hiệu

quan sát được trên màn hình.

7

Page 8: Bao Cao Radar

4. Tính năng kỹ thuật của Radar:

- Vùng quan sát: Radar có nhiệm vụ quan sát mục tiêu trong phạm vi này.

Vùng quan sát giới hạn bởi cự ly cực đại Dmax và cực tiểu Dmin và các

góc quan sát trong mặt phẳng ngang và đứng.

- Chu kỳ quét Tq: là thời gian để Radar quét hết vùng quan sát một lần.

- Các tọa độ được đo.

- Độ chính xác đo các tọa độ và tốc độ mục tiêu.

- Độ tin cậy sử dụng: độ tin cậy nêu lên khả năng hoàn thành chức năng

của đài trong một khoảng thời gian xác định. Thông thường độ tin cậy

được biểu thị bởi xác suất đài làm việc trong một khoảng thời gian đã

cho.

- Khả năng chống nhiễu: là khả năng duy trì được các chỉ tiêu kỹ thuật của

đài Radar trong điều khiển có nhiễu tác động.

- Về tính năng chiến thuật đôi khi người ta còn kể them những điều kiện

làm việc của đài: tính chất của mục tiêu, điều kiện thời tiết, vị trí triển

khai..

- Các tính năng chiến thuật của đài radar xác định bởi tính năng kỹ thuật

của nó.

- Nguyên tắc xây dựng đài Radar: phương pháp nhận tín hiệu Radar, dạng

dao động bức xạ, phương pháp gia công tín hiệu trong máy thu.

- Tần số sóng mang của dao động bức xạ hay bước sóng λ.

- Quy luật điều chế dao động bức xạ.

- Công suất bức xạ trung bình Ptb và công suất đỉnh Pd.

- Dạng và độ rộng của giản đồ anten.

8

Page 9: Bao Cao Radar

- Độ nhạy của máy thu theo công suất Ptmin hay năng lượng.

5. Nguyên lý đo khoảng cách, vận tốc của mục tiêu :

- Để đo khoảng cách, radar dùng sóng điện từ cao tần (sóng radio) phát vào

không gian dưới dạng xung radio và thu lại sóng phản xạ từ mục tiêu về.

Khi đó ta có công thức:

Trong đó: D: Khoảng cách từ radar đến mục tiêu

C: tốc độ truyền sóng ( )

t: Thời gian truyền sóng (đi và phản xạ trở về)

- Để đo được góc mạn của mục tiêu, khi anten quay và phát sóng vào

không gian thám sát mục tiêu thì trên màn ảnh tia quét cũng quay theo.

Người ta thiết kế sao cho tia quét và radar có cùng tốc độ quay. Đồng

thời, radar phải cùng lúc bao quát được cả khu vực quanh chủ thể và đảm

bảo phân biệt được các mục tiêu ở các hướng khác nhau khi chúng không

nằm dính vào nhau. Do đó người ta thiết kế sao cho anten quay tròn 360

độ và có tính định hướng sóng phát: anten radar bức xạ sóng điện từ vào

không gian có giản đồ phát hình búp với đặc trưng là góc mở ngang n

và góc mở đứng d. Thông thường:

n = 005 ÷ 30

d = 200 ÷ 300

- Để tính tốc độ của mục tiêu, ta dựa vào hiện tượng dịch tần số doppler.

9

Page 10: Bao Cao Radar

Ta có công thức tính dịch tần doppler:

Với:

Dựa vào hình vẽ trên dẫn đến:

Dẫn đến vận tốc mục tiêu:

Trong không gian:

10

Page 11: Bao Cao Radar

II. PHẦN MỀM MÔ PHỎNG:

11

Page 12: Bao Cao Radar

1. Yêu cầu của đề bài:

Mô phỏng màn hình hiển thị mục tiêu Radar trên máy tính ( sử

dụng ngôn ngữ Visual C# 2008)

- Hiển thị được 6 mục tiêu cùng một lúc bằng 6 màu khác nhau.

- Để lại dấu vết của quỹ đạo mục tiêu.

- Radar chủ động sơ cấp quét tròn (toàn phương), vừa có thể quét ngược cũng

như quét thuận.

- Tự động bám sát một mục tiêu bất kỳ nào đó (bám theo góc phương vị).

- Có giới hạn Dmax, Dmin.

- Lần lượt mô phỏng trên 4 trang màn hình

Hiển thị nhìn vòng.

Hiển thị cự ly D bằng cách quét tia điện tử đường thẳng( giống oxilo).

Hiển thị cự ly D bằng cách quét tia điện tử vòng tròn.

Hiển thị cự ly D bằng cách quét tia điện tử xoắn ốc.

Phải thể hiện được độ chính xác theo mức độ tăng dần.

- Radar tự động đảo chiều quét cánh sóng khi có lệnh.

2. Thuật toán mô phỏng:

12

Page 13: Bao Cao Radar

3. Viết chương trình sử dụng Visual Studio 2008 – ngôn ngữ C#:

Mã nguồn chương trình mô phỏng Radar:

a.Program.csusing System;using System.Collections.Generic;using System.Linq;using System.Windows.Forms;

namespace Radar_display{ static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false);

13

Page 14: Bao Cao Radar

Application.Run(new Interface()); } }}

b.Radar.csusing 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 Radar_display;namespace iRadar{

public class Radar { public int abc; public static int target = 0; public DataGridView tableMuctieu; public Radar_display.Interface mainfrm; public circlescan cs; public spiralscan ss; public Linearscan ls; public bool quet_thuan = true; public int IDitemBamsat = -1;

static int _size; // biến tĩnh

Image _baseImage; // ảnh nền Image _outputImage; // ảnh hiển thị trên picturebox public int _az = 0; // góc phương vị

PointF _pt = new PointF(0F, 0F); PointF _pt2 = new PointF(2F, 2F); PointF _pt3 = new PointF(0.5F, 0.5F); // 3 điểm quét của cánh sóng

Timer t;

bool _scanLine = false;//?

//màu nền Color _topColor = Color.FromArgb(0, 50, 0); Color _bottomColor = Color.FromArgb(0, 50, 0);

14

Page 15: Bao Cao Radar

Color _lineColor = Color.FromArgb(0, 255, 0);//màu của đường trên hình vẽ

// list of radar items public List<RadarItem> radarItemList = new List<RadarItem>(); public List<MuctieuData> mtData = new List<MuctieuData>(); ListView lvTarget = new ListView(); List<int> MuctieuID = new List<int>();

public Radar(int duongkinh) { // set the diameter of the control // this influences the size of the output image _size = duongkinh; // biến này = bề độ picture1 do code trong interface... // create the base image CreateBaseImage(); // create the export image Draw(); // set up the default timer intervals // the timer is used for the scanline drawing // it is also disabled by default t = new Timer(); t.Tick += new EventHandler(t_Tick); t.Interval = 100;// biến interval<khoảng thời gian ?> để làm gì...? }

public int DrawScanInterval//tia quét {

get { return t.Interval; } set { // update the timer interval if (value > 0) t.Interval = value; } }

public bool DrawScanLine// quét { get { return _scanLine; } set { _scanLine = value; // turn the timer on/off t.Enabled = _scanLine; // if the user turns off the scanline, redraw the image if (!_scanLine)

15

Page 16: Bao Cao Radar

Draw(); } } public Image Image { get { return _outputImage; } }

#region tạo ảnh chính void CreateBaseImage() {

Image i = new Bitmap(_size, _size); Graphics g = Graphics.FromImage(i); Pen p = new Pen(_lineColor);

g.CompositingQuality = CompositingQuality.HighQuality; g.InterpolationMode = InterpolationMode.Bicubic; g.SmoothingMode = SmoothingMode.AntiAlias; g.TextRenderingHint = TextRenderingHint.AntiAlias;

// draw the background of the radar // với ... 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)//vẽ đường tròn ngoài // ve vong ngoai (goc ngang = 0°), cung chinh la vong tron to nhat g.DrawEllipse(p, 0, 0, _size - 1, _size - 1);

// draw the inner ring (60° elevation)//vẽ đường tròn phía trong int interval = _size / 5;// interval = 500/5 = 100; 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.Yellow, interval1 / 2, _size / 2);// giá trị trục trái g.DrawString((30 - 6 * j).ToString() + "0", ab, Brushes.Yellow, _size - interval1 / 2 - 15, _size / 2);// giá trị trục phải }

//draw (x,y) axis g.DrawLine(p, new Point(0, (int)(_size / 2)), new Point(_size - 1, (int)(_size / 2))); //truc x g.DrawLine(p, new Point((int)(_size / 2), 0), new Point((int)(_size / 2), _size - 1)); //truc y Font abc = new Font("Arial", 12); g.DrawString("W", abc, Brushes.Yellow, 0, _size / 2); g.DrawString("N", abc, Brushes.Yellow, _size / 2, 0); g.DrawString("E", abc, Brushes.Yellow, _size - 15, _size / 2); g.DrawString("S", abc, Brushes.Yellow, _size / 2, _size - 15);

16

Page 17: Bao Cao Radar

// release the graphics object g.Dispose(); // update the base image (phải có) _baseImage = i; }

#endregion

// Draws the output image and fire the event caller for ImageUpdate

void Draw() { // copy of baseImage Image i = (Image)_baseImage.Clone();

Graphics g = Graphics.FromImage(i); GraphicsPath path = new GraphicsPath(); path.FillMode = FillMode.Winding; path.AddEllipse(-1F, -1F, (float)(_size + 1), (float)(_size + 1));

g.Clip = new Region(path);

// hiển thị đẹp hơn g.CompositingQuality = CompositingQuality.HighQuality; g.InterpolationMode = InterpolationMode.Bicubic; g.SmoothingMode = SmoothingMode.AntiAlias; g.TextRenderingHint = TextRenderingHint.AntiAlias;

if (_scanLine) { //chú ý pt là nằm giữa,pt2 bên phải,pt3 bên trái do AzRg2XY quyết định // fading GraphicsPath gp = new GraphicsPath(FillMode.Winding); gp.AddLine(new PointF((float)(_size / 2), (float)(_size / 2)), _pt); //gp.AddLine(new PointF((float)(_size / 2), (float)(_size / 2)), _pt2); //gp.AddCurve(new PointF[] { _pt2, _pt3, _pt }); gp.AddLine(_pt3, new PointF((float)(_size / 2), (float)(_size / 2))); PathGradientBrush pgb = new PathGradientBrush(gp); pgb.CenterPoint = _pt;//vị trí màu đậm nhất của cánh pgb.CenterColor = Color.FromArgb(240, _lineColor); pgb.SurroundColors = new Color[] { Color.Empty }; // draw the fade path g.FillPath(pgb, gp); // draw the scanline //g.DrawLine(new Pen(_lineColor), new PointF((float)(_size / 2), (float)(_size / 2)), _pt); //tia đậm nhất // draw each RadarItem in the list abc = getAzimuth(_pt);

if (IDitemBamsat != -1) { int radarAz = getAzimuth(_pt);//tia để kiểm soát mục tiêu int itemAz = radarItemList[IDitemBamsat].Azimuth;

17

Page 18: Bao Cao Radar

if (itemAz > radarAz - 2 && itemAz < radarAz + 2) { if (getRange(radarItemList[IDitemBamsat].currentPoint()) < _size / 2 && getRange(radarItemList[IDitemBamsat].currentPoint()) > 30) { radarItemList[IDitemBamsat].DrawItem(this, g); _baseImage = radarItemList[IDitemBamsat].SaveItem(_baseImage); } } if (radarAz < 10) radarAz += 360; if (itemAz < 10) itemAz += 360; if (radarAz > (itemAz + 10)) quet_thuan = false; if (radarAz < (itemAz - 10)) quet_thuan = true; } //quet cac muc tieu hien tai foreach (RadarItem item in radarItemList) { //neu muc tieu nam trong canh song cua radar thi hien thi tren man hinh va hien thi tren list if (item.Azimuth > getAzimuth(_pt3)-30 && item.Azimuth < getAzimuth(_pt3)+2 ) { if (getRange(item.currentPoint()) < _size/2 && getRange(item.currentPoint()) > 30) { if (!MuctieuID.Exists(element => element == item.ID)) { MuctieuID.Add(item.ID); doAddtoTable(item);

} else { doUpdateTable(item); }

item.DrawItem(this, g); //============================================== _baseImage = item.SaveItem(_baseImage); } }

} } // draw the outer ring once more g.DrawEllipse(new Pen(_lineColor), 0, 0, _size - 1, _size - 1);

g.Dispose(); OnImageUpdate(i);

_outputImage = i; }

18

Page 19: Bao Cao Radar

public void doUpdateTable(RadarItem item) { for (int i = 0; i < mainfrm.tableMuctieu.Rows.Count - 1; i++) { if (Int32.Parse(mainfrm.tableMuctieu.Rows[i].Cells[0].Value.ToString()) == item.ID) mainfrm.tableMuctieu.Rows[i].SetValues(new Object[5] { (Object)item.ID, item.Azimuth, item.Height, item.Range, item.Velocity }); }

for (int i = 0; i < mtData.Count; i++) { if (mtData[i].ID == item.ID) { mtData[i].Range = item.Range; cs.Draw(mtData); ls.Draw(mtData); ss.Draw(mtData); } } }

public void doAddtoTable(RadarItem item) { Object[] newRow = new Object[6]; try { newRow[0] = (Object)item.ID; newRow[1] = (Object)item.color.ToArgb(); newRow[2] = (Object)item.Azimuth; newRow[3] = (Object)item.Height; newRow[4] = (Object)item.Range; newRow[5] = (Object)item.Velocity; } catch (Exception abc) { return; } mainfrm.tableMuctieu.Rows.Add(newRow); mainfrm.tableMuctieu.Rows[mainfrm.tableMuctieu.Rows.Count-2].DefaultCellStyle.BackColor = item.color; mtData.Add(new MuctieuData(item.ID,item.color,item.Range)); cs.Draw(mtData); ls.Draw(mtData); ss.Draw(mtData); } public PointF AzRg2XY(int azimuth, int Rg) { // rotate coords... 90deg W = 180deg trig double angle = (270d + (double)azimuth);

// turn into radians angle *= 0.0174532925d;

19

Page 20: Bao Cao Radar

double r, x, y;

// determine the lngth of the radius r = Rg;

x = (((double)_size * 0.5d) + (r * Math.Cos(angle))); y = (((double)_size * 0.5d) + (r * Math.Sin(angle)));

return new PointF((float)x, (float)y); }

public static int getAzimuth(PointF pt) { double r, x, y; r = _size * 0.5d;//ban kinh duong tron //xac dinh toa do so voi tam x = pt.X - r; y = pt.Y - r; double canh_huyen = Math.Sqrt(x * x + y * y); //tinh goc so voi truc x double angle = Math.Acos(x / canh_huyen); //doi sang do. angle = angle / 0.0174532925d;

if (y < 0) { angle = 360d - angle; } //chuyen sang goc so voi truc. y - Phuong BAC'

double azimuth = angle - 270d; if (azimuth < 0) azimuth = azimuth + 360d; return (int)azimuth; } public static bool isNummeric(string str) { char[] chr = str.ToCharArray(); foreach (char ch in chr) { if ('0' > ch || ch > '9') return false;

} return true; }

public static int getRange(PointF pt) { double x, y; x = pt.X - _size / 2; y = pt.Y - _size / 2; int range = (int)Math.Sqrt(x * x + y * y); return range; }

20

Page 21: Bao Cao Radar

public void AddItem(RadarItem item) { bool bFlag = true;

for (int i = 0; i < radarItemList.Count; i++) { if (radarItemList[i].ID == item.ID) radarItemList[i] = item; //else radarItemList.Add(item); }

if (bFlag) radarItemList.Add(item); item.Azimuth = getAzimuth(item.From); item.Range = getRange(item.From); Draw(); }

void t_Tick(object sender, EventArgs e) { for (int i = 0; i < radarItemList.Count - 1; i++) for (int j = i + 1; j < radarItemList.Count; j++) { if (radarItemList[i].Height == radarItemList[j].Height) { doUpdateTable(radarItemList[i]); doUpdateTable(radarItemList[j]); radarItemList.RemoveAt(j); radarItemList.RemoveAt(i); } } // increment the azimuth if (quet_thuan) { _az++; } else { _az--; } // reset the azimuth if needed if (_az >= 360) _az = 0;

// update the fade path coordinates _pt = AzRg2XY(_az, _size); _pt2 = AzRg2XY(_az - 30, _size); _pt3 = AzRg2XY(_az + 30, _size);

// redraw the output image Draw();

21

Page 22: Bao Cao Radar

}

/// <summary> /// Event caller for the ImageUpdate event /// </summary> /// <param name="i"></param> private void OnImageUpdate(Image i) { if (ImageUpdate != null) ImageUpdate(this, new ImageUpdateEventArgs(i)); }

/// <summary> /// Event fired when the output image is redrawn /// </summary> public event ImageUpdateHandler ImageUpdate;

} public delegate void ImageUpdateHandler(object sender, ImageUpdateEventArgs e);

public class ImageUpdateEventArgs : EventArgs { Image _image;

public Image Image { get { return _image; } }

public ImageUpdateEventArgs(Image i) { _image = i; } }

}

c.RadarItem.csusing 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;

22

Page 23: Bao Cao Radar

using Radar_display;namespace iRadar{

public class Radar { public int abc; public static int target = 0; public DataGridView tableMuctieu; public Radar_display.Interface mainfrm; public circlescan cs; public spiralscan ss; public Linearscan ls; public bool quet_thuan = true; public int IDitemBamsat = -1;

static int _size; // biến tĩnh

Image _baseImage; // ảnh nền Image _outputImage; // ảnh hiển thị trên picturebox public int _az = 0; // góc phương vị

PointF _pt = new PointF(0F, 0F); PointF _pt2 = new PointF(2F, 2F); PointF _pt3 = new PointF(0.5F, 0.5F); // 3 điểm quét của cánh sóng

Timer t;

bool _scanLine = false;//?

//màu nền Color _topColor = Color.FromArgb(0, 50, 0); Color _bottomColor = Color.FromArgb(0, 50, 0); Color _lineColor = Color.FromArgb(0, 255, 0);//màu của đường trên hình vẽ

// list of radar items public List<RadarItem> radarItemList = new List<RadarItem>(); public List<MuctieuData> mtData = new List<MuctieuData>(); ListView lvTarget = new ListView(); List<int> MuctieuID = new List<int>();

public Radar(int duongkinh) { // set the diameter of the control // this influences the size of the output image _size = duongkinh; // biến này = bề độ picture1 do code trong interface... // create the base image CreateBaseImage(); // create the export image

23

Page 24: Bao Cao Radar

Draw(); // set up the default timer intervals // the timer is used for the scanline drawing // it is also disabled by default t = new Timer(); t.Tick += new EventHandler(t_Tick); t.Interval = 100;// biến interval<khoảng thời gian ?> để làm gì...? }

public int DrawScanInterval//tia quét {

get { return t.Interval; } set { // update the timer interval if (value > 0) t.Interval = value; } }

public bool DrawScanLine// quét { get { return _scanLine; } set { _scanLine = value; // turn the timer on/off t.Enabled = _scanLine; // if the user turns off the scanline, redraw the image if (!_scanLine) Draw(); } } public Image Image { get { return _outputImage; } }

#region tạo ảnh chính void CreateBaseImage() {

Image i = new Bitmap(_size, _size);

24

Page 25: Bao Cao Radar

Graphics g = Graphics.FromImage(i); Pen p = new Pen(_lineColor);

g.CompositingQuality = CompositingQuality.HighQuality; g.InterpolationMode = InterpolationMode.Bicubic; g.SmoothingMode = SmoothingMode.AntiAlias; g.TextRenderingHint = TextRenderingHint.AntiAlias;

// draw the background of the radar // với ... 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)//vẽ đường tròn ngoài // ve vong ngoai (goc ngang = 0°), cung chinh la vong tron to nhat g.DrawEllipse(p, 0, 0, _size - 1, _size - 1);

// draw the inner ring (60° elevation)//vẽ đường tròn phía trong int interval = _size / 5;// interval = 500/5 = 100; 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.Yellow, interval1 / 2, _size / 2);// giá trị trục trái g.DrawString((30 - 6 * j).ToString() + "0", ab, Brushes.Yellow, _size - interval1 / 2 - 15, _size / 2);// giá trị trục phải }

//draw (x,y) axis g.DrawLine(p, new Point(0, (int)(_size / 2)), new Point(_size - 1, (int)(_size / 2))); //truc x g.DrawLine(p, new Point((int)(_size / 2), 0), new Point((int)(_size / 2), _size - 1)); //truc y Font abc = new Font("Arial", 12); g.DrawString("W", abc, Brushes.Yellow, 0, _size / 2); g.DrawString("N", abc, Brushes.Yellow, _size / 2, 0); g.DrawString("E", abc, Brushes.Yellow, _size - 15, _size / 2); g.DrawString("S", abc, Brushes.Yellow, _size / 2, _size - 15); // release the graphics object g.Dispose(); // update the base image (phải có) _baseImage = i; }

#endregion

// Draws the output image and fire the event caller for ImageUpdate

void Draw() { // copy of baseImage Image i = (Image)_baseImage.Clone();

Graphics g = Graphics.FromImage(i); GraphicsPath path = new GraphicsPath();

25

Page 26: Bao Cao Radar

path.FillMode = FillMode.Winding; path.AddEllipse(-1F, -1F, (float)(_size + 1), (float)(_size + 1));

g.Clip = new Region(path);

// hiển thị đẹp hơn g.CompositingQuality = CompositingQuality.HighQuality; g.InterpolationMode = InterpolationMode.Bicubic; g.SmoothingMode = SmoothingMode.AntiAlias; g.TextRenderingHint = TextRenderingHint.AntiAlias;

if (_scanLine) { //chú ý pt là nằm giữa,pt2 bên phải,pt3 bên trái do AzRg2XY quyết định // fading GraphicsPath gp = new GraphicsPath(FillMode.Winding); gp.AddLine(new PointF((float)(_size / 2), (float)(_size / 2)), _pt); //gp.AddLine(new PointF((float)(_size / 2), (float)(_size / 2)), _pt2); //gp.AddCurve(new PointF[] { _pt2, _pt3, _pt }); gp.AddLine(_pt3, new PointF((float)(_size / 2), (float)(_size / 2))); PathGradientBrush pgb = new PathGradientBrush(gp); pgb.CenterPoint = _pt;//vị trí màu đậm nhất của cánh pgb.CenterColor = Color.FromArgb(240, _lineColor); pgb.SurroundColors = new Color[] { Color.Empty }; // draw the fade path g.FillPath(pgb, gp); // draw the scanline //g.DrawLine(new Pen(_lineColor), new PointF((float)(_size / 2), (float)(_size / 2)), _pt); //tia đậm nhất // draw each RadarItem in the list abc = getAzimuth(_pt);

if (IDitemBamsat != -1) { int radarAz = getAzimuth(_pt);//tia để kiểm soát mục tiêu int itemAz = radarItemList[IDitemBamsat].Azimuth; if (itemAz > radarAz - 2 && itemAz < radarAz + 2) { if (getRange(radarItemList[IDitemBamsat].currentPoint()) < _size / 2 && getRange(radarItemList[IDitemBamsat].currentPoint()) > 30) { radarItemList[IDitemBamsat].DrawItem(this, g); _baseImage = radarItemList[IDitemBamsat].SaveItem(_baseImage); } } if (radarAz < 10) radarAz += 360; if (itemAz < 10) itemAz += 360; if (radarAz > (itemAz + 10)) quet_thuan = false; if (radarAz < (itemAz - 10)) quet_thuan = true; } //quet cac muc tieu hien tai

26

Page 27: Bao Cao Radar

foreach (RadarItem item in radarItemList) { //neu muc tieu nam trong canh song cua radar thi hien thi tren man hinh va hien thi tren list if (item.Azimuth > getAzimuth(_pt3)-30 && item.Azimuth < getAzimuth(_pt3)+2 ) { if (getRange(item.currentPoint()) < _size/2 && getRange(item.currentPoint()) > 30) { if (!MuctieuID.Exists(element => element == item.ID)) { MuctieuID.Add(item.ID); doAddtoTable(item);

} else { doUpdateTable(item); }

item.DrawItem(this, g); //============================================== _baseImage = item.SaveItem(_baseImage); } }

} } // draw the outer ring once more g.DrawEllipse(new Pen(_lineColor), 0, 0, _size - 1, _size - 1);

g.Dispose(); OnImageUpdate(i);

_outputImage = i; }

public void doUpdateTable(RadarItem item) { for (int i = 0; i < mainfrm.tableMuctieu.Rows.Count - 1; i++) { if (Int32.Parse(mainfrm.tableMuctieu.Rows[i].Cells[0].Value.ToString()) == item.ID) mainfrm.tableMuctieu.Rows[i].SetValues(new Object[5] { (Object)item.ID, item.Azimuth, item.Height, item.Range, item.Velocity }); }

for (int i = 0; i < mtData.Count; i++) { if (mtData[i].ID == item.ID) { mtData[i].Range = item.Range; cs.Draw(mtData); ls.Draw(mtData); ss.Draw(mtData);

27

Page 28: Bao Cao Radar

} } }

public void doAddtoTable(RadarItem item) { Object[] newRow = new Object[6]; try { newRow[0] = (Object)item.ID; newRow[1] = (Object)item.color.ToArgb(); newRow[2] = (Object)item.Azimuth; newRow[3] = (Object)item.Height; newRow[4] = (Object)item.Range; newRow[5] = (Object)item.Velocity; } catch (Exception abc) { return; } mainfrm.tableMuctieu.Rows.Add(newRow); mainfrm.tableMuctieu.Rows[mainfrm.tableMuctieu.Rows.Count-2].DefaultCellStyle.BackColor = item.color; mtData.Add(new MuctieuData(item.ID,item.color,item.Range)); cs.Draw(mtData); ls.Draw(mtData); ss.Draw(mtData); } public PointF AzRg2XY(int azimuth, int Rg) { // rotate coords... 90deg W = 180deg trig double angle = (270d + (double)azimuth);

// turn into radians angle *= 0.0174532925d;

double r, x, y;

// determine the lngth of the radius r = Rg;

x = (((double)_size * 0.5d) + (r * Math.Cos(angle))); y = (((double)_size * 0.5d) + (r * Math.Sin(angle)));

return new PointF((float)x, (float)y); }

public static int getAzimuth(PointF pt) { double r, x, y; r = _size * 0.5d;//ban kinh duong tron //xac dinh toa do so voi tam x = pt.X - r;

28

Page 29: Bao Cao Radar

y = pt.Y - r; double canh_huyen = Math.Sqrt(x * x + y * y); //tinh goc so voi truc x double angle = Math.Acos(x / canh_huyen); //doi sang do. angle = angle / 0.0174532925d;

if (y < 0) { angle = 360d - angle; } //chuyen sang goc so voi truc. y - Phuong BAC'

double azimuth = angle - 270d; if (azimuth < 0) azimuth = azimuth + 360d; return (int)azimuth; } public static bool isNummeric(string str) { char[] chr = str.ToCharArray(); foreach (char ch in chr) { if ('0' > ch || ch > '9') return false;

} return true; }

public static int getRange(PointF pt) { double x, y; x = pt.X - _size / 2; y = pt.Y - _size / 2; int range = (int)Math.Sqrt(x * x + y * y); return range; }

public void AddItem(RadarItem item) { bool bFlag = true;

for (int i = 0; i < radarItemList.Count; i++) { if (radarItemList[i].ID == item.ID) radarItemList[i] = item; //else radarItemList.Add(item); }

if (bFlag) radarItemList.Add(item); item.Azimuth = getAzimuth(item.From); item.Range = getRange(item.From); Draw(); }

29

Page 30: Bao Cao Radar

void t_Tick(object sender, EventArgs e) { for (int i = 0; i < radarItemList.Count - 1; i++) for (int j = i + 1; j < radarItemList.Count; j++) { if (radarItemList[i].Height == radarItemList[j].Height) { doUpdateTable(radarItemList[i]); doUpdateTable(radarItemList[j]); radarItemList.RemoveAt(j); radarItemList.RemoveAt(i); } } // increment the azimuth if (quet_thuan) { _az++; } else { _az--; } // reset the azimuth if needed if (_az >= 360) _az = 0;

// update the fade path coordinates _pt = AzRg2XY(_az, _size); _pt2 = AzRg2XY(_az - 30, _size); _pt3 = AzRg2XY(_az + 30, _size);

// redraw the output image Draw();

}

/// <summary> /// Event caller for the ImageUpdate event /// </summary> /// <param name="i"></param> private void OnImageUpdate(Image i) { if (ImageUpdate != null) ImageUpdate(this, new ImageUpdateEventArgs(i)); }

/// <summary> /// Event fired when the output image is redrawn /// </summary> public event ImageUpdateHandler ImageUpdate;

30

Page 31: Bao Cao Radar

} public delegate void ImageUpdateHandler(object sender, ImageUpdateEventArgs e);

public class ImageUpdateEventArgs : EventArgs { Image _image;

public Image Image { get { return _image; } }

public ImageUpdateEventArgs(Image i) { _image = i; } }

}

d.Typescan.csusing System.Text;using System.Drawing;using System.Drawing.Design;using System.Drawing.Drawing2D;using System.Drawing.Imaging;using System.Drawing.Text;using System.Windows.Forms;using iRadar;using System.Collections.Generic;using System;

namespace Radar_display{ // quét thẳng public class Linearscan { static int _size; Image _baseImage; public Image outImage; public bool quet_thuan = true;

List<RadarItem> radarItemList = new List<RadarItem>(); //ListView lvTarget = new ListView(); Radar _radar; public Linearscan(Radar radar, int diameter) { this._radar = radar;

31

Page 32: Bao Cao Radar

radarItemList = _radar.radarItemList; _size = diameter; CreateBaseImage();

}

void CreateBaseImage() { Image i = new Bitmap(_size, _size); Graphics g = Graphics.FromImage(i); // output image look nice g.CompositingQuality = CompositingQuality.HighQuality; g.InterpolationMode = InterpolationMode.Bicubic; g.SmoothingMode = SmoothingMode.AntiAlias; g.TextRenderingHint = TextRenderingHint.AntiAlias;

Pen mypen = new Pen(Color.FromArgb(0, 255, 0)); Color _topColor = Color.FromArgb(0, 120, 0); Color _bottomColor = Color.FromArgb(0, 40, 0); g.FillRectangle(new LinearGradientBrush(new Point((int)(_size / 2), 0), new Point((int)(_size / 2), _size - 1), _topColor, _bottomColor), 0, 10, _size - 1, 220); //const int _Num = 20; int cx = _size; //int cy = _size; //vong tron to ban kinh 225 points

Font abc = new Font("Arial", 8); g.DrawLine(mypen, cx / 14, 60, cx * 13 / 14, 60); for (int sr = 0; sr <= 3; sr++) { g.DrawLine(mypen, cx / 14 + sr * cx * 4 / 14, 60 - 3, cx / 14 + sr * cx * 4 / 14, 60 + 3); g.DrawString((sr * 100).ToString(), abc, Brushes.LightYellow, cx / 14 - 7 + sr * cx * 4 / 14, 60 - 17);

} g.DrawLine(mypen, cx / 14, 180, cx * 13 / 14, 180); for (int sr = 0; sr <= 10; sr++) { g.DrawLine(mypen, cx / 14 + sr * cx * 12 / 140, 180 - 3, cx / 14 + sr * cx * 12 / 140, 180 + 3); g.DrawString((sr * 10).ToString(), abc, Brushes.LightYellow, cx / 14 - 7 + sr * cx * 12 / 140, 180 - 17); }

// release the graphics object g.Dispose(); // update the base image _baseImage = i; }

public void Draw(List<MuctieuData> mtData) { Image i = (Image)_baseImage.Clone(); // create the circular path for clipping the output Graphics g = Graphics.FromImage(i);

32

Page 33: Bao Cao Radar

// output image look nice g.CompositingQuality = CompositingQuality.HighQuality; g.InterpolationMode = InterpolationMode.Bicubic; g.SmoothingMode = SmoothingMode.AntiAlias; g.TextRenderingHint = TextRenderingHint.AntiAlias;

foreach (MuctieuData item in mtData) { // vẽ mục tiêu (hình gì đó) trên hình, // với khoảng cách đến radar là item.Range // màu là item.color; float d = (float)(item.Range * _size * 12 / 14 / 300); //quy doi khoang cach g.FillRectangle(new SolidBrush(item.color), _size / 14 + d - 3, 60 - 5, 6, 10); //g.DrawRectangle(p2,100, while (d >= _size * 4 / 14) { d -= _size * 4 / 14; } g.FillRectangle(new SolidBrush(item.color), _size / 14 + d * 3 - 3, 180 - 5, 6, 10); // g.DrawEllipse(new Pen(item.color, 2), item.Range, 100, 50, 50); }

outImage = i; OnImageUpdate(i); }

#region Outgoing Event Code

/// <summary> /// Event caller for the ImageUpdate event /// </summary> /// <param name="i"></param> private void OnImageUpdate(Image i) { if (ImageUpdate != null) ImageUpdate(this, new ImageUpdateEventArgs(i)); }

/// <summary> /// Event fired when the output image is redrawn /// </summary> public event ImageUpdateHandler ImageUpdate;

#endregion }

// quét xoắn public class spiralscan { static int _size; Image _baseImage; public Image outImage;

33

Page 34: Bao Cao Radar

public bool quet_thuan = true; List<RadarItem> radarItemList = new List<RadarItem>(); //ListView lvTarget = new ListView(); Radar _radar; public spiralscan(Radar radar, int diameter) { this._radar = radar; radarItemList = _radar.radarItemList; _size = diameter; CreateBaseImage(); }

void CreateBaseImage() { // create the drawing objects Image i = new Bitmap(_size, _size); Graphics g = Graphics.FromImage(i); Pen p1 = new Pen(Color.Green, 2); Pen p2 = new Pen(Color.LightGreen, 2);

Color _topColor = Color.FromArgb(0, 120, 0); Color _bottomColor = Color.FromArgb(0, 24, 0); // set a couple of graphics properties to make the // output image look nice g.CompositingQuality = CompositingQuality.HighQuality; g.InterpolationMode = InterpolationMode.Bicubic; g.SmoothingMode = SmoothingMode.AntiAlias; g.TextRenderingHint = TextRenderingHint.AntiAlias; 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);

Pen mypen = new Pen(Color.FromArgb(0, 255, 0), 2); //const int _Num = 20; int cx = _size; //int cy = _size; int thaydoixoan = 8; PointF[] points = new PointF[cx * thaydoixoan * 2]; float angle = 0; //float temp = 1, step = 1; ; //so vong xoan = cx*4/360;

for (int j = 0; j < cx * thaydoixoan; j++) {

points[j].X = cx / 2 + (float)(j / (thaydoixoan * 2 + 2) * Math.Cos(angle * Math.PI / 180)); points[j].Y = cx / 2 + (float)(j / (thaydoixoan * 2 + 2) * Math.Sin(angle * Math.PI / 180)); angle += 1f; if (angle > 360) angle -= 360; if (j > 0) g.DrawLine(mypen, points[j - 1], points[j]); //temp+=step; //step *= (float)101/100; } /* chia ti le ko deu*/

34

Page 35: Bao Cao Radar

Font abc = new Font("Arial", 10); for (int j = 0; j <= cx * thaydoixoan; j += (int)(cx * thaydoixoan / 10)) //10 la so diem lay moc, vidu 0,30,60,... { if (j == cx * thaydoixoan) { g.DrawEllipse(mypen, points[j - 1].X - 2, points[j - 1].Y - 2, 4, 4); g.DrawString(((int)(j * 30 / (int)(cx * thaydoixoan / 10))).ToString(), abc, Brushes.LightYellow, points[cx * thaydoixoan - 1].X, points[cx * thaydoixoan - 1].Y); } else { g.DrawEllipse(mypen, points[j].X - 2, points[j].Y - 2, 4, 4); g.DrawString(((int)(j * 30 / (int)(cx * thaydoixoan / 10))).ToString(), abc, Brushes.LightYellow, points[j].X, points[j].Y); } } /* End of chia ti le ko deu */ // release the graphics object g.Dispose(); // update the base image _baseImage = i; }

public void Draw(List<MuctieuData> mtData) { Image i = (Image)_baseImage.Clone(); // create the circular path for clipping the output Graphics g = Graphics.FromImage(i); GraphicsPath path = new GraphicsPath(); path.FillMode = FillMode.Winding; path.AddEllipse(-1F, -1F, (float)(_size + 1), (float)(_size + 1)); // clip the output image to the circular shape g.Clip = new Region(path); // set a couple of graphics properties to make the // output image look nice g.CompositingQuality = CompositingQuality.HighQuality; g.InterpolationMode = InterpolationMode.Bicubic; g.SmoothingMode = SmoothingMode.AntiAlias; g.TextRenderingHint = TextRenderingHint.AntiAlias; int cx = _size; int thaydoixoan = 4; PointF[] points = new PointF[cx * thaydoixoan * 2]; /*chia ti le deu, giai phuong trinh bac 2*/ /* float angle = 0; // float temp = 1, step = 1; ; double spiral_length = Math.PI * (cx * thaydoixoan - 1) * (cx * thaydoixoan) / 3600; for (int j = 0; j < cx * thaydoixoan; j++) { points[j].X = cx / 2 + (float)(j / (thaydoixoan * 2 + 2) * Math.Cos(angle * Math.PI / 180)); points[j].Y = cx / 2 + (float)(j / (thaydoixoan * 2 + 2) * Math.Sin(angle * Math.PI / 180)); angle += 1; if (angle > 360) angle -= 360;

35

Page 36: Bao Cao Radar

} foreach (MuctieuData item in mtData) { // vẽ mục tiêu (hình gì đó) trên hình, // với khoảng cách đến radar là item.Range // màu là item.color; double location = gptb2(item.Range * spiral_length / 300); g.DrawEllipse(new Pen(item.color), points[(int)location].X-2, points[(int)location].Y-2, 8, 8); //g.DrawEllipse(new Pen(item.color, 2), item.Range, item.Range, 50, 50); } */

/* Chia ti le ko deu */ float angle = 0; for (int j = 0; j < cx * thaydoixoan; j++) { points[j].X = cx / 2 + (float)(j / (thaydoixoan * 2 + 2) * Math.Cos(angle * Math.PI / 180)); points[j].Y = cx / 2 + (float)(j / (thaydoixoan * 2 + 2) * Math.Sin(angle * Math.PI / 180)); angle += 1; if (angle > 360) angle -= 360; } foreach (MuctieuData item in mtData) { // vẽ mục tiêu (hình gì đó) trên hình, // với khoảng cách đến radar là item.Range // màu là item.color; double spiral_length = Math.PI * (cx * thaydoixoan - 1) * (cx * thaydoixoan) / 180 / 2 / (thaydoixoan * 2 + 2); double location = (item.Range * spiral_length / 300);//khoang cach toi tam, da quy doi theo he toa do xoan. location = gptb2(location);//quy doi tu khoang cach ra so thu tu cua diem trong mang points; g.FillEllipse(new SolidBrush(item.color), points[(int)location].X - 5, points[(int)location].Y - 5, 10, 10);

//g.DrawEllipse(new Pen(item.color, 2), item.Range, item.Range, 50, 50); }

outImage = i; OnImageUpdate(i); } double gptb2(double t) { double delta = (1 + 4 * 3600 * t / Math.PI); double sqrdelta = Math.Sqrt(delta); return (1 + sqrdelta) / 2; //MessageBox.Show("delta la : " + delta, "ududu"); }

void t_Tick(object sender, EventArgs e) { Image i = (Image)_baseImage.Clone(); // create the circular path for clipping the output Graphics g = Graphics.FromImage(i); GraphicsPath path = new GraphicsPath();

36

Page 37: Bao Cao Radar

path.FillMode = FillMode.Winding; path.AddEllipse(-1F, -1F, (float)(_size + 1), (float)(_size + 1)); // clip the output image to the circular shape g.Clip = new Region(path); // set a couple of graphics properties to make the // output image look nice g.CompositingQuality = CompositingQuality.HighQuality; g.InterpolationMode = InterpolationMode.Bicubic; g.SmoothingMode = SmoothingMode.AntiAlias; g.TextRenderingHint = TextRenderingHint.AntiAlias;

Pen p2 = new Pen(Color.LightGreen, 2); int cx = _size; int cy = _size; PointF[] points = new PointF[cx * 5]; float angle = 0; // float temp = 1, step = 1; ; double spiral_length = Math.PI * (cx * 4 - 1) * (cx * 4) / 3600; for (int j = 0; j < cx * 20 / 5; j++) {

points[j].X = cx / 2 + (float)(j / 10 * Math.Cos(angle * Math.PI / 180)); points[j].Y = cy / 2 + (float)(j / 10 * Math.Sin(angle * Math.PI / 180)); angle += 1; if (angle > 360) angle -= 360; } //g.DrawLines(mypen, points); foreach (RadarItem item in radarItemList) { double khoangcach = Math.Sqrt((item.currentPoint().X - 250) * (item.currentPoint().X - 250) + (item.currentPoint().Y - 250) * (item.currentPoint().Y - 250)); double location = gptb2(khoangcach * spiral_length / 250); g.DrawEllipse(new Pen(Brushes.Red), points[(int)location].X, points[(int)location].Y, 4, 4);

}

outImage = i; OnImageUpdate(i); /* if (quet_thuan) { az++; } else { az--; } if (az > 359) az = 0; if (az < 0) az = 359; */

} #region Outgoing Event Code

/// <summary>

37

Page 38: Bao Cao Radar

/// Event caller for the ImageUpdate event /// </summary> /// <param name="i"></param> private void OnImageUpdate(Image i) { if (ImageUpdate != null) ImageUpdate(this, new ImageUpdateEventArgs(i)); }

/// <summary> /// Event fired when the output image is redrawn /// </summary> public event ImageUpdateHandler ImageUpdate;

#endregion }

//quét tròn public class circlescan { static int _size; Image _baseImage; public Image outImage; public bool quet_thuan = true;

List<RadarItem> radarItemList = new List<RadarItem>();

Radar _radar; public circlescan(Radar radar, int diameter) { this._radar = radar; radarItemList = _radar.radarItemList; _size = diameter; CreateBaseImage(); }

void CreateBaseImage() { // create the drawing objects Image i = new Bitmap(_size, _size); Graphics g = Graphics.FromImage(i); Pen p1 = new Pen(Color.Green, 2); Pen p2 = new Pen(Color.LightGreen, 2); Pen penx = new Pen(Color.Green, 1);

Color _topColor = Color.FromArgb(0, 120, 0); Color _bottomColor = Color.FromArgb(0, 40, 0); // set a couple of graphics properties to make the // output image look nice g.CompositingQuality = CompositingQuality.HighQuality; g.InterpolationMode = InterpolationMode.Bicubic; g.SmoothingMode = SmoothingMode.AntiAlias; g.TextRenderingHint = TextRenderingHint.AntiAlias;

38

Page 39: Bao Cao Radar

// draw the background of the radar //g.DrawLines(p1, new PointF[] { new PointF(_size / 2, _size / 2), new PointF(_size / 2 - 15, _size - 20), new PointF(_size / 2 + 15, _size - 20), new PointF(_size / 2, _size / 2) });

Pen mypen = new Pen(Color.FromArgb(0, 255, 0), 2); //const int _Num = 20; int cx = _size; //int cy = _size; //vong tron to ban kinh 225 points 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); g.FillEllipse(new SolidBrush(Color.LightGreen), _size / 2, _size / 2, 2, 2); //g.DrawLine(penx, new Point(0, (int)(_size / 2)), new Point(_size - 1, (int)(_size / 2))); //truc x //g.DrawLine(penx, new Point((int)(_size / 2), 0), new Point((int)(_size / 2), _size - 1)); //truc y

g.DrawEllipse(mypen, cx / 10, cx / 10, 8 * cx / 10, 8 * cx / 10); g.DrawEllipse(mypen, 3 * cx / 10, 3 * cx / 10, 4 * cx / 10, 4 * cx / 10); PointF[] points = new PointF[400]; Font abc = new Font("Arial", 8); for (int p = 0; p < 360; p++) { //points[0] co toa do 250,25 points[p].X = (float)(cx / 2 + 4 * cx / 10 * Math.Sin((double)p * Math.PI / 180)); points[p].Y = (float)(cx / 2 - 4 * cx / 10 * Math.Cos((double)p * Math.PI / 180)); } for (int p = 0; p < 360; p += 30) { g.DrawString(((int)(p * 25 / 30)).ToString(), abc, Brushes.LightYellow, points[p].X, points[p].Y);

} for (int p = 0; p < 360; p += 36) { g.DrawString(((int)(p / 36)).ToString(), abc, Brushes.LightYellow, cx / 2 + (points[p].X - cx / 2) / 2, cx / 2 + (points[p].Y - cx / 2) / 2); }

// release the graphics object g.Dispose(); // update the base image _baseImage = i; }

public void Draw(List<MuctieuData> mtData) { Image i = (Image)_baseImage.Clone(); // create the circular path for clipping the output Graphics g = Graphics.FromImage(i); GraphicsPath path = new GraphicsPath(); path.FillMode = FillMode.Winding; path.AddEllipse(-1F, -1F, (float)(_size + 1), (float)(_size + 1)); // clip the output image to the circular shape g.Clip = new Region(path); // set a couple of graphics properties to make the // output image look nice g.CompositingQuality = CompositingQuality.HighQuality;

39

Page 40: Bao Cao Radar

g.InterpolationMode = InterpolationMode.Bicubic; g.SmoothingMode = SmoothingMode.AntiAlias; g.TextRenderingHint = TextRenderingHint.AntiAlias; int cx = _size; PointF[] points = new PointF[400]; for (int p = 0; p < 360; p++) { //points[0] co toa do 250,25 points[p].X = (float)(cx / 2 + 4 * cx / 10 * Math.Sin((double)p * Math.PI / 180)); points[p].Y = (float)(cx / 2 - 4 * cx / 10 * Math.Cos((double)p * Math.PI / 180)); } foreach (MuctieuData item in mtData) { // vẽ mục tiêu (hình gì đó) trên hình, // với khoảng cách đến radar là item.Range // màu là item.color; double angle = ((double)item.Range) / 300 * 360;

g.FillEllipse(new SolidBrush(item.color), points[((int)angle)].X - 5, points[((int)angle)].Y - 5, 10, 10); while (angle >= 120) { angle -= 120; } int angle_ = (int)angle * 3; g.FillEllipse(new SolidBrush(item.color), (points[angle_].X - cx / 2) / 2 - 5 + cx / 2, (points[angle_].Y - cx / 2) / 2 + cx / 2 - 5, 10, 10); //g.DrawEllipse(new Pen(item.color, 2), item.Range, item.Range, 50, 50); }

outImage = i; OnImageUpdate(i); }

#region Outgoing Event Code

/// <summary> /// Event caller for the ImageUpdate event /// </summary> /// <param name="i"></param> private void OnImageUpdate(Image i) { if (ImageUpdate != null) ImageUpdate(this, new ImageUpdateEventArgs(i)); }

/// <summary> /// Event fired when the output image is redrawn /// </summary> public event ImageUpdateHandler ImageUpdate;

#endregion }

40

Page 41: Bao Cao Radar

}

4.Kết quả thu được:

Giao diện màn hình chính:

41

Page 42: Bao Cao Radar

Hiển thị thông tin mục tiêu trên giao diện:

Hiển thị mục tiêu theo đường quét thẳng:

42

Page 43: Bao Cao Radar

Hiển thị mục tiêu theo đường quét tròn:

Hiển thị mục tiêu theo đường quét xoắn ốc:

43

Page 44: Bao Cao Radar

Chế độ điều khiển tốc độ quét cánh sóng của radar và thay đổi chiều quét của radar

Chế độ bám sát mục tiêu của radar:

- Bằng cách ấn chọn mục tiêu trên thanh giao diện, rồi ấn nút bám sát, màn hình radar sẽ tự động đưa cánh sóng bám sát mục tiêu vừa chọn..

44

Page 45: Bao Cao Radar

5 .Kết luận, nhận xét và đánh giá:

- Mô phỏng thành công màn hình radar.- Thực hiện chính xác các yêu cầu đã đề ra với phần mềm mô phỏng- Giao diện gọn nhẹ, đơn giản, dễ sử dụng.- Các chức năng còn đơn giản nhưng mô tả rõ được những chức năng cơ bản

của radar. Phần mềm của nhóm em còn thô sơ, mong thầy nhận xét đóng góp ý kiến để

chúng em có thể hoàn thành tốt công việc ở những bài tập lớn tiếp theo…!

45