飞行航迹规划程序
1、8字型航迹
8字型航迹指的是飞行器在空中按照8字型轨迹飞行的航迹规划方式。
这种航迹规划方式通常应用于需要对某个目标进行跟踪或拍摄的任务,比如摄像任务。由于8字型航迹可以保持飞行器在目标周围飞行,从而可以更好地进行跟踪和拍摄。
此外,8字型航迹还具有较好的稳定性和可控性,可以保证飞行器在规定区域内进行持续拍摄。
以下是一个简单的C++代码示例。
1 #include <iostream>
2 #include <vector>
3 #include <cmath>
4 #include <fstream>
5
6
7 using namespace std;
8 #define PI 3.1415926
9
10 struct MyPoint
11 {
12 double x;
13 double y;
14 };
15
16 vector<MyPoint> getCircle_point(double center_x, double center_y, double Dire_angle, double width, int N)
17 {
18 vector<MyPoint>circle1_point, circle2_point; // 创建点的数组
19 MyPoint mypoint1, mypoint2; // 实例化的点
20
21
22 // 计算圆心坐标
23 double radius = width/2 ; // 圆心半径
24 // 第一个圆的圆心坐标
25 double radius_x1 = center_x + cos(Dire_angle) * radius;
26 double radius_y1 = center_y + sin(Dire_angle) * radius;
27
28 // 第二个圆的圆心坐标
29 double radius_x2 = center_x - cos(Dire_angle) * radius;
30 double radius_y2 = center_y - sin(Dire_angle) * radius;
31
32 double cur_angle1(0.0), cur_angle2(0.0);
33 double single_angle = 2 * PI / N; // 间隔多少度进行计算一个点位(弧度)
34
35 for (int i = 0; i < N; i++)
36 {
37 cur_angle1 = PI + Dire_angle - single_angle * i;
38 if (cur_angle1 > 2 * PI)
39 {
40 cur_angle1 = cur_angle1 - 2 * PI;
41 }
42
43 if (cur_angle1 < 0)
44 {
45 cur_angle1 = cur_angle1 + 2 * PI;
46 }
47
48 mypoint1.x = cos(cur_angle1) * radius + radius_x1;
49 mypoint1.y = sin(cur_angle1) * radius + radius_y1;
50 circle1_point.push_back(mypoint1);
51
52
53 cur_angle2 = Dire_angle + single_angle * i;
54 if (cur_angle2 > 2 * PI)
55 {
56 cur_angle2 = cur_angle2 - 2 * PI;
57 }
58
59 mypoint2.x = cos(cur_angle2) * radius + radius_x2;
60 mypoint2.y = sin(cur_angle2) * radius + radius_y2;
61 circle2_point.push_back(mypoint2);
62 }
63 circle1_point.insert(circle1_point.end(),circle2_point.begin(), circle2_point.end());
64 return circle1_point;
65
66 }
67
68
69 int main()
70 {
71 double Dire_angle = 45 * PI / 180 ; // 方向角
72 double center_x = 0.0, center_y = 0.0; // 第一个航点
73 double width = 200.0; // 宽(直径)
74 double length = 500.0; // 长
75 double interval = 25; // 间隔
76
77 int N = 40; // 计算圆上的点位个数
78 vector<MyPoint>result1 = getCircle_point(center_x, center_y, Dire_angle, width, N);
79
80 return 0;
81 }
保存到txt中,再导入excel中绘图结果如下:
2、线段轨迹
飞行器按照线段轨迹飞行。
1 #include <iostream>
2 #include <vector>
3 #include <cmath>
4 #include <fstream>
5
6
7 using namespace std;
8 #define PI 3.1415926
9
10 struct MyPoint
11 {
12 double x;
13 double y;
14 };
15
16 vector<MyPoint>getLine_point(double center_x, double center_y, double Dire_angle, double length, int N1)
17 {
18 vector<MyPoint>line_point; // 创建点的数组
19 MyPoint mypoint; // 实例化的点
20
21 double line_dist;
22 double line_interval = length / N1; // 两个采样点的间隔距离
23
24 double begin_x = center_x + length / 2 * cos(Dire_angle);
25 double begin_y = center_y + length / 2 * sin(Dire_angle);
26
27 for (int ii = 0; ii <= N1; ii++)
28 {
29 line_dist = line_interval * ii;
30
31 mypoint.x = begin_x - line_dist * cos(Dire_angle);
32 mypoint.y = begin_y - line_dist * sin(Dire_angle);
33
34 line_point.push_back(mypoint);
35 }
36 return line_point;
37 }
38
39 int main()
40 {
41 double Dire_angle = 45 * PI / 180 ; // 方向角
42 double center_x = 0.0, center_y = 0.0; // 第一个航点
43 double width = 200.0; // 宽(直径)
44 double length = 500.0; // 长
45 double interval = 25; // 间隔
46
47 int N1 = 9; // 计算线段上的点位个数
48 vector<MyPoint>result2 = getLine_point(center_x, center_y, Dire_angle, length, N1);
49
50 return 0;
51 }
3、圆盘顺(逆)
圆形航迹指的是飞行器在空中按照圆形轨迹飞行的航迹规划方式。这种航迹规划方式通常应用于需要保持一定航向的任务,比如巡逻任务。
由于圆形航迹的半径和速度可以根据任务需求进行调整,因此可以更好地满足任务的实际需求。
此外,圆形航迹还具有较好的稳定性和可控性,可以保证飞行器在规定区域内进行持续巡逻。
1 #include <iostream>
2 #include <vector>
3 #include <cmath>
4 #include <fstream>
5
6
7 using namespace std;
8 #define PI 3.1415926
9
10 struct MyPoint
11 {
12 double x;
13 double y;
14 };
15
16 vector<MyPoint>getorder_point(double center_x, double center_y, double width, int N2)
17 {
18 vector<MyPoint>order_point; // 创建点的数组
19 MyPoint round_point; // 实例化的点
20
21 // 计算圆心坐标
22 double radius = width / 2; // 圆心半径
23 double single_angle = 2 * PI / N2; // 间隔多少度进行计算一个点位(弧度)
24 double round_angle = 0.0;
25
26 for (int iii = 0; iii < N2; iii++)
27 {
28 round_angle = PI / 2 - single_angle * iii;
29 if (round_angle < 0)
30 {
31 round_angle = round_angle + PI * 2;
32 }
33
34 round_point.x = center_x + radius * cos(round_angle);
35 round_point.y = center_y + radius * sin(round_angle);
36 order_point.push_back(round_point);
37
38 }
39 return order_point;
40 }
41
42 vector<MyPoint>getReve_order_point(double center_x, double center_y, double width, int N3)
43 {
44 vector<MyPoint>reve_order_point; // 创建点的数组
45 MyPoint round_point; // 实例化的点
46
47 // 计算圆心坐标
48 double radius = width / 2; // 圆心半径
49 double single_angle = 2 * PI / N3; // 间隔多少度进行计算一个点位(弧度)
50 double round_angle = 0.0;
51
52 for (int j = 0; j < N3; j++)
53 {
54 round_angle = PI / 2 + single_angle * j;
55 if (round_angle > 2 * PI)
56 {
57 round_angle = round_angle - PI * 2;
58 }
59
60 round_point.x = center_x + radius * cos(round_angle);
61 round_point.y = center_y + radius * sin(round_angle);
62 reve_order_point.push_back(round_point);
63
64 }
65 return reve_order_point;
66 }
67
68
69 int main()
70 {
71 double Dire_angle = 45 * PI / 180 ; // 方向角
72 double center_x = 0.0, center_y = 0.0; // 第一个航点
73 double width = 200.0; // 宽(直径)
74 double length = 500.0; // 长
75 double interval = 25; // 间隔
76
77 int N2 = 40; // 计算圆顺盘上的点位个数
78 vector<MyPoint>result3 = getorder_point(center_x, center_y, width, N2);
79
80 int N3 = 40; // 计算圆逆盘上的点位个数
81 vector<MyPoint>result4 = getReve_order_point(center_x, center_y, width, N3);
82
83 return 0;
84 }
4、跑道圆顺(逆)
跑道形航迹指的是飞行器在空中按照跑道形轨迹飞行的航迹规划方式。这种航迹规划方式通常应用于需要在规定区域内进行搜索或侦察的任务,比如侦察任务。
由于跑道形航迹可以保持飞行器在规定区域内进行持续搜索或侦察,从而可以更好地满足任务需求。
此外,跑道形航迹还具有较好的稳定性和可控性,可以保证飞行器在规定区域内进行持续搜索或侦察。
1 #include <iostream>
2 #include <vector>
3 #include <cmath>
4 #include <fstream>
5
6
7 using namespace std;
8 #define PI 3.1415926
9
10 struct MyPoint
11 {
12 double x;
13 double y;
14 };
15
16
17 vector<MyPoint>getorder_runway(double center_x, double center_y, double Dire_angle, double length, double width, int N4, int N5)
18 {
19 vector<MyPoint>circle1_point, circle2_point, line1_point, line2_point; // 创建点的数组
20 MyPoint mypoint1, mypoint2, linepoint1, linepoint2; // 实例化的点
21
22 // 第一个圆的圆心坐标
23 double radius_x1 = center_x + cos(Dire_angle) * (length - width) / 2;
24 double radius_y1 = center_y + sin(Dire_angle) * (length - width) / 2;
25
26 // 第二个圆的圆心坐标
27 double radius_x2 = center_x - cos(Dire_angle) * (length - width) / 2;
28 double radius_y2 = center_y - sin(Dire_angle) * (length - width) / 2;
29
30 double radius = width / 2; // 圆心半径
31 double single_angle = PI / N4;
32 double cur_angle1(0.0), cur_angle2(0.0);
33
34 for (int jj = 0; jj <= N4; jj++)
35 {
36 cur_angle1 = PI / 2 + Dire_angle - single_angle * jj;
37 if (cur_angle1 > 2 * PI)
38 {
39 cur_angle1 = cur_angle1 - 2 * PI;
40 }
41 if (cur_angle1 < 0)
42 {
43 cur_angle1 = cur_angle1 + 2 * PI;
44 }
45 mypoint1.x = cos(cur_angle1) * radius + radius_x1;
46 mypoint1.y = sin(cur_angle1) * radius + radius_y1;
47 circle1_point.push_back(mypoint1);
48
49 cur_angle2 = PI / 2 + PI + Dire_angle - single_angle * jj;
50 if (cur_angle2 > 2 * PI)
51 {
52 cur_angle2 = cur_angle2 - 2 * PI;
53 }
54 mypoint2.x = cos(cur_angle2) * radius + radius_x2;
55 mypoint2.y = sin(cur_angle2) * radius + radius_y2;
56 circle2_point.push_back(mypoint2);
57 }
58
59 double line_dist;
60
61 double line_interval = (length - width) / N5; // 跑道圆线段上两点之间的间隔
62
63 double begin_x1 = radius_x1 + cos(Dire_angle + 3 * PI / 2)* radius;
64 double begin_y1 = radius_y1 + sin(Dire_angle + 3 * PI / 2)* radius;
65
66 double begin_x2 = radius_x2 + cos(Dire_angle + PI / 2) * radius;
67 double begin_y2 = radius_y2 + sin(Dire_angle + PI / 2) * radius;
68
69 for (int jjj = 1; jjj < N5; jjj++)
70 {
71 line_dist = line_interval * jjj;
72
73 linepoint1.x = begin_x1 - line_dist * cos(Dire_angle);
74 linepoint1.y = begin_y1 - line_dist * sin(Dire_angle);
75 line1_point.push_back(linepoint1);
76
77
78 linepoint2.x = begin_x2 + line_dist * cos(Dire_angle);
79 linepoint2.y = begin_y2 + line_dist * sin(Dire_angle);
80 line2_point.push_back(linepoint2);
81 }
82 circle1_point.insert(circle1_point.end(), line1_point.begin(), line1_point.end());
83 circle1_point.insert(circle1_point.end(), circle2_point.begin(), circle2_point.end());
84 circle1_point.insert(circle1_point.end(), line2_point.begin(), line2_point.end());
85 return circle1_point;
86 }
87
88 vector<MyPoint>getReve_order_runway(double center_x, double center_y, double Dire_angle, double length, double width, int N6, int N7)
89 {
90 vector<MyPoint>circle1_point, circle2_point, line1_point, line2_point; // 创建点的数组
91 MyPoint mypoint1, mypoint2, linepoint1, linepoint2; // 实例化的点
92
93
94 // 第一个圆的圆心坐标
95 double radius_x1 = center_x + cos(Dire_angle) * (length - width) / 2;
96 double radius_y1 = center_y + sin(Dire_angle) * (length - width) / 2;
97
98 // 第二个圆的圆心坐标
99 double radius_x2 = center_x - cos(Dire_angle) * (length - width) / 2;
100 double radius_y2 = center_y - sin(Dire_angle) * (length - width) / 2;
101
102 double radius = width / 2; // 圆心半径
103 double cur_angle1(0.0), cur_angle2(0.0);
104 cur_angle1 = Dire_angle + PI / 2;
105
106 double begin_x1 = radius_x1 + cos(cur_angle1) * radius;
107 double begin_y1 = radius_y1 + sin(cur_angle1) * radius;
108
109 cur_angle2 = Dire_angle + 3 * PI / 2;
110 double begin_x2 = radius_x2 + cos(cur_angle2) * radius;
111 double begin_y2 = radius_y2 + sin(cur_angle2) * radius;
112
113 double line_dist;
114 double line_interval = (length - width) / N7; // 跑道圆线段上两点之间的间隔
115
116 for (int ij = 0; ij < N7; ij++)
117 {
118 line_dist = line_interval * ij;
119
120 linepoint1.x = begin_x1 - line_dist * cos(Dire_angle);
121 linepoint1.y = begin_y1 - line_dist * sin(Dire_angle);
122 line1_point.push_back(linepoint1);
123
124 linepoint2.x = begin_x2 + line_dist * cos(Dire_angle);
125 linepoint2.y = begin_y2 + line_dist * sin(Dire_angle);
126 line2_point.push_back(linepoint2);
127 }
128
129 double single_angle = PI / N6;
130
131 for (int iij = 0; iij < N6; iij++)
132 {
133 cur_angle1 = PI + PI / 2 + Dire_angle + single_angle * iij;
134 if (cur_angle1 > 2 * PI)
135 {
136 cur_angle1 = cur_angle1 - 2 * PI;
137 }
138 mypoint1.x = cos(cur_angle1) * radius + radius_x1;
139 mypoint1.y = sin(cur_angle1) * radius + radius_y1;
140 circle1_point.push_back(mypoint1);
141
142 cur_angle2 = PI / 2 + Dire_angle + single_angle * iij;
143 if (cur_angle2 > 2 * PI)
144 {
145 cur_angle2 = cur_angle2 - 2 * PI;
146 }
147 mypoint2.x = cos(cur_angle2) * radius + radius_x2;
148 mypoint2.y = sin(cur_angle2) * radius + radius_y2;
149 circle2_point.push_back(mypoint2);
150 }
151 line1_point.insert(line1_point.end(), circle2_point.begin(), circle2_point.end());
152 line1_point.insert(line1_point.end(), line2_point.begin(), line2_point.end());
153 line1_point.insert(line1_point.end(), circle1_point.begin(), circle1_point.end());
154 return line1_point;
155 }
156
157 int main()
158 {
159 double Dire_angle = 45 * PI / 180 ; // 方向角
160 double center_x = 0.0, center_y = 0.0; // 第一个航点
161 double width = 200.0; // 宽(直径)
162 double length = 50.0; // 长
163 double interval = 25; // 间隔
164
165 - int N4 = 20, N5 = 10; // 跑道半圆上的点位个数与线段上的点位个数
166 vector<MyPoint>result5 = getorder_runway(center_x, center_y, Dire_angle, length, width, N4, N5);
167
168 int N6 = 20, N7 = 10; // 跑道逆半圆上的点位个数与线段上的点位个数
169 vector<MyPoint>result6 = getReve_order_runway(center_x, center_y, Dire_angle, length, width, N6, N7);
170
171 vector<MyPoint>::iterator start = result5.begin();//指向容器的初始位置
172 vector<MyPoint>::iterator end = result5.end();//指向元素最后一个位置的后一个位置
173
174 // 向txt文档中写入数据
175 ofstream dataFile;
176 dataFile.open("dataFile.txt", ofstream::app);
177 fstream file("dataFile.txt", ios::out);
178
179 while (start != end)
180 {
181 dataFile<<start->x<<",\t"<<start->y<<endl; // 写入数据
182 cout << start->x << ", "<< start->y << endl;
183 start++;
184
185 }
186 dataFile.close(); // 关闭文档
187
188
189 return 0;
190 }
5、弓形(蛇形)轨迹
弓形航迹:飞行器按照弓形轨迹飞行,通常应用于需要进行避障或者规避其他飞行器的任务。
1 #include <iostream>
2 #include <vector>
3 #include <cmath>
4 #include <fstream>
5
6
7 using namespace std;
8 #define PI 3.1415926
9
10 struct MyPoint
11 {
12 double x;
13 double y;
14 };
15
16
17 vector<MyPoint>getserpentine_point(double center_x, double center_y, double Dire_angle, double length, double width, double interval, int N8)
18 {
19 vector<MyPoint>serpentine_point; // 创建点的数组
20 MyPoint mypoint; // 实例化的点
21
22 int num = floor(width / interval);
23 double new_width = floor(width / interval) * interval; // 计算宽度除以间隔取整后的新宽度
24 double line_dist;
25 double line_interval = length / N8; // 两个采样点的间隔距离
26
27 double begin_x0 = center_x - cos(PI / 2 - Dire_angle) * new_width / 2 + sin(PI / 2 - Dire_angle) * length / 2;
28 double begin_y0 = center_y + sin(PI / 2 - Dire_angle) * new_width / 2 + cos(PI / 2 - Dire_angle) * length / 2;
29
30 mypoint.x = begin_x0;
31 mypoint.y = begin_y0;
32 serpentine_point.push_back(mypoint);
33 double begin_x1, begin_y1, begin_x2, begin_y2, begin_x3, begin_y3, begin_x4, begin_y4, begin_x5, begin_y5;
34
35 for (int i = 1; i <= num; i++)
36 {
37 if (i % 2 != 0)
38 {
39 begin_x1 = serpentine_point.back().x;
40 begin_y1 = serpentine_point.back().y;
41 for (int j = 1; j <= N8; j++)
42 {
43 line_dist = line_interval * j;
44
45 mypoint.x = begin_x1 - line_dist * cos(Dire_angle);
46 mypoint.y = begin_y1 - line_dist * sin(Dire_angle);
47 serpentine_point.push_back(mypoint);
48 }
49 begin_x2 = serpentine_point.back().x;
50 begin_y2 = serpentine_point.back().y;
51
52 for (int jj = 1; jj <= N8; jj++)
53 {
54 line_dist = line_interval * jj;
55 mypoint.x = begin_x2 + line_dist * cos(PI / 2 - Dire_angle);
56 mypoint.y = begin_y2 - line_dist * sin(PI / 2 - Dire_angle);
57 serpentine_point.push_back(mypoint);
58 }
59 }
60 else
61 {
62 begin_x3 = serpentine_point.back().x;
63 begin_y3 = serpentine_point.back().y;
64 for (int z = 1; z <= N8; z++)
65 {
66 line_dist = line_interval * z;
67
68 mypoint.x = begin_x3 + line_dist * cos(Dire_angle);
69 mypoint.y = begin_y3 + line_dist * sin(Dire_angle);
70 serpentine_point.push_back(mypoint);
71 }
72 begin_x4 = serpentine_point.back().x;
73 begin_y4 = serpentine_point.back().y;
74
75 for (int zz = 1; zz <= N8; zz++)
76 {
77 line_dist = line_interval * zz;
78 mypoint.x = begin_x4 + line_dist * cos(PI / 2 - Dire_angle);
79 mypoint.y = begin_y4 - line_dist * sin(PI / 2 - Dire_angle);
80 serpentine_point.push_back(mypoint);
81 }
82 }
83 }
84
85 if (num % 2 == 0)
86 {
87 begin_x5 = serpentine_point.back().x;
88 begin_y5 = serpentine_point.back().y;
89 for (int ij = 1; ij <= N8; ij++)
90 {
91 line_dist = line_interval * ij;
92
93 mypoint.x = begin_x5 - line_dist * cos(Dire_angle);
94 mypoint.y = begin_y5 - line_dist * sin(Dire_angle);
95 serpentine_point.push_back(mypoint);
96 }
97 }
98 else
99 {
100 begin_x5 = serpentine_point.back().x;
101 begin_y5 = serpentine_point.back().y;
102 for (int ij = 1; ij <= N8; ij++)
103 {
104 line_dist = line_interval * ij;
105
106 mypoint.x = begin_x5 + line_dist * cos(Dire_angle);
107 mypoint.y = begin_y5 + line_dist * sin(Dire_angle);
108 serpentine_point.push_back(mypoint);
109 }
110 }
111 return serpentine_point;
112 }
113
114 int main()
115 {
116 double Dire_angle = 45 * PI / 180 ; // 方向角
117 double center_x = 0.0, center_y = 0.0; // 第一个航点
118 double width = 200.0; // 宽(直径)
119 double length = 50.0; // 长
120 double interval = 25; // 间隔
121
122 int N8 = 10;
123 vector<MyPoint>result7 = getserpentine_point(center_x, center_y, Dire_angle, length, width, interval, N8);
124
125
126 vector<MyPoint>::iterator start = result7.begin();//指向容器的初始位置
127 vector<MyPoint>::iterator end = result7.end();//指向元素最后一个位置的后一个位置
128
129 // 向txt文档中写入数据
130 ofstream dataFile;
131 dataFile.open("dataFile.txt", ofstream::app);
132 fstream file("dataFile.txt", ios::out);
133
134 while (start != end)
135 {
136 dataFile<<start->x<<",\t"<<start->y<<endl; // 写入数据
137 cout << start->x << ", "<< start->y << endl;
138 start++;
139
140 }
141 dataFile.close(); // 关闭文档
142
143
144 return 0;
145 }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了