2.1 问题一的分析
2.1.1 接收信号定位模型的建立与求解 题目要求被动接受信号无人机的定位模型。由题目分析可知 10 架无人机的理想 坐标,其中FY00位于圆心,从FY01到FY09的角度坐标依次增加为40°。已知在 圆形编队中,无人机FY00和编队中另两架无人机发射信号,其余无人机被动接收信 号,且无人机接收到的信号仅为与发射信号无人机连线的夹角信息,这些夹角信息是 定位模型的关键。通过应用几何学的正弦定理进行三角定位,就可以根据这些夹角以 及无人机在编队中的固定编号和相对位置关系来构建包含三大类情况的定位模型,从 而可以计算出接收无人机的具体位置坐标。
2.1.2 最小需求量定位 题目要求实现有效定位的发射信号无人机数量。为了确保无人机在圆形编队中的 有效定位,除了已知的FY00和FY01无人机外,我们还需要进一步探讨额外需要多少架无人机发射信号。这一问题涉及到对接收无人机与发射无人机之间夹角信息的充 分利用和几何关系的深入分析。通过分类讨论发射无人机情况,选取特殊的位置情况, 并构建相应的几何关系模型,证明特殊情况假设的数量能确保接收无人机获得足够的 信息进行精确定位。
2.1.3 圆周上无人机调整方案 题目要求实现圆形编队无人机位置调整方案。基于问题(1)的圆形定位模型,已 知圆上三架无人机位置可实现接收信号无人机定位。题目给出所有无人机初始位置, 我们发现位于半径为98m的圆上有三架,而位于半径为100m的圆上仅为2架,出于 对误差的考虑,以98m的圆为目标圆形编队。先对98m圆上的FY02、FY05、FY08 调整位置,然后选择偏差较小的两架与FY00作为发射信号无人机,利用局部搜索算 法调整其他无人机位置,调整完一次再根据位置误差选择较小的两架与FY00作为新 的发射信号无人机,迭代调整,直至算法将收敛到一个局部最优解,使编队形态最接近理想解。
2.2 问题二的分析 题目要求实现锥形编队的无人机位置调整方案。首先由题目给出的锥型编队示意 图可知相邻无人机之间的间距和无人机的总数量,以及它们之间的初始位置关系。由 于锥形编队的几何关系,假设FY05在理想位置,利用三角定位和前面的定位模型调 整获取周围无人机的相对位置信息,最后再调整顶点无人机位置,调整位置同样使用 局部搜索算法,通过不断尝试和调整无人机的位置,以最小化编队整体的偏差为目标。算法在搜索过程中会不断评估当前编队形态与理想锥形编队之间的差距,并通过迭代的方式逐步逼近最优解。最终让无人机达到整体为锥形编队。
第一问代码
while True:
import re
print("输入角度只需输入前面数字即可,例如30°,直接输入30")
while True:
A = input("请输入第一架飞机的编号:")
B = input("请输入第二架飞机的编号:")
C = input("请输入要求飞机的编号:")
if len(A) != 4 or len(B) != 4 or len(C) != 4:
print("编码输出有误,请按规定重新输入")
continue
else :
q = int(A[3])
p = int(B[3])
t = int(C[3])
print(q,p,t)
break
list_bianhao=['(100,0)', '(100,40)', '(100,80)', '(100,120)', '(100,160)', '(100,200)', '(100,240)', '(100,280)', '(100,320)']
list_bianhao[q-1] =
result = re.findall(r"\((.*?)\)",第一架飞机极坐标为)
lisA = result[0]
lisB = lisA.split(",")
a = int(lisB[1])#第一架飞机的角度
print(a)
r = int(lisB[0])
list_bianhao[p-1] =
result = re.findall(r"\((.*?)\)", 第二架飞机极坐标为)
lisA = result[0]
lisB = lisA.split(",")
b = int(lisB[1])#第二架飞机的角度
print(b)
list_bianhao[t-1] =
result = re.findall(r"\((.*?)\)",要求飞机的预期极坐标为)
lisA = result[0]
lisB = lisA.split(",")
c = int(lisB[1])#预计飞机的角度
print(c)
import sympy as sy
import numpy as np
import math
A1 = int(input("a1的角度:"))
A2 = int(input("a2的角度:"))
A3 = int(input("a3的角度:"))
if a>b :#算出的两家飞机的夹角z
if b != 0:
z = math.radians(a-b)
s1 = math.radians(a)
s2 = math.radians(b)
else :
z = math.radians(a)
s1 = math.radians(a)
s2 = 0
else :
if a != 0:
z = math.radians(b-a)
s1 = math.radians(b)
s2 = math.radians(a)
else :
z = math.radians(b)
s1 = math.radians(b)
s2 = 0
a1 = math.radians(A1)
a2 = math.radians(A2)
a3 = math.radians(A3)
if min(a,b)>c :
if max(a,b)-c<180 :
o = math.atan((math.sin(a1)*math.sin(a1+a2+s2)-math.sin(a1+s1)*math.sin(a1+a2))/(math.sin(a1)*math.cos(a2+a1+s2)-math.cos(a1+s1)*math.sin(a2+a1)))
jiaodu = math.degrees(o)
if c<90:
jiaodu1=jiaodu
s=o
elif c<=270:
jiaodu1=jiaodu+180
s=o+math.pi
elif c<=360:
jiaodu1 = 360 + jiaodu
s = 2 * math.pi + o
op = abs(r*math.sin(a1+s1-s)/math.sin(a1))
.2f},{:.2f}°)".format(op,jiaodu1)) :
print("1")
elif max(a,b)- c>180 and min(a,b)-c<180 :
o = math.atan((-math.sin(a2) * math.sin(a1-s1)+math.sin(a1)*math.sin(a2+s2)) / (math.sin(a1) * math.cos(a2 + s2) + math.cos(a1 - s1) * math.sin(a2)))
jiaodu = math.degrees(o)
if c < 90:
jiaodu1 = jiaodu
s = o
elif c <= 270:
jiaodu1 = jiaodu + 180
s = o + math.pi
elif c <= 360:
jiaodu1 = 360 + jiaodu
s = 2 * math.pi + o
op = abs(r * math.sin(a2 + s2 - s)/ math.sin(a2))
.2f},{:.2f}°)".format(op, jiaodu1)) :
print("2")
elif min(a,b)-c>180 :
o = math.atan((math.sin(a2) * math.sin(a1 + a2 - s1) - math.sin(a1 + a2) * math.sin(a2 - s2)) / (math.sin(a1+a2) * math.cos(a2 - s2) - math.cos(a1 + a2 - s1) * math.sin(a2)))
jiaodu = math.degrees(o)
if c<90:
jiaodu1=jiaodu
s=o
elif c<=270:
jiaodu1=jiaodu+180
s=o+math.pi
elif c<=360:
jiaodu1 = 360 + jiaodu
s = 2 * math.pi + o
op = abs(r * math.sin(a2 + s -s2)/ math.sin(a2))
.2f},{:.2f}°)".format(op, jiaodu1)) :
print("3")
elif max(a,b)>c>min(a,b) :
if max(a,b)-c<180 and c-min(a,b)<180:
o = math.atan((-math.sin(a1)*math.sin(a2-s2)+math.sin(a2)*math.sin(a1+s1))/(math.sin(a2)*math.cos(a1+s1)+math.sin(a1)*math.cos(a2-s2)))
jiaodu = math.degrees(o)
if c<90:
jiaodu1=jiaodu
s=o
elif c<=270:
jiaodu1=jiaodu+180
s=o+math.pi
elif c<=360:
jiaodu1 = 360 + jiaodu
s = 2 * math.pi + o
op = abs(r * math.sin(a1 + s1 - s) / math.sin(a1))
.2f},{:.2f}°)".format(op, jiaodu1)) :
print("4")
elif max(a,b)-c >= 180 and min(a,b)-c < 180 :
o = math.atan((math.sin(a1)*math.sin(a1+a2-s2)-math.sin(a1-s1)*math.sin(a1+a2)) / (math.sin(a1+a2) * math.cos(a1-s1)-math.sin(a1)*math.cos(a1+a2-s2)))
jiaodu = math.degrees(o)
print(jiaodu)
if c<90:
jiaodu1=jiaodu
s=o
elif c<=270:
jiaodu1=jiaodu+180
s=o+math.pi
elif c <= 360:
jiaodu1 = 360 + jiaodu
s = 2 * math.pi + o
op = abs(r * math.sin(a1 - s1 + s) / math.sin(a1))
.2f},{:.2f}°)".format(op, jiaodu1)) :
print("5")
elif max(a,b)-c <180 and c- min(a,b)> 180 :
o = math.atan((math.sin(a1+a2) * math.sin(a2 + s2) - math.sin(a2) * math.sin(a1 +a2 + s1)) / (math.sin(a1 + a2) * math.cos(a2 + s2) - math.sin(a2) * math.cos(a1 + a2 + s1)))
jiaodu= math.degrees(o)
print(jiaodu)
if c<90:
jiaodu1=jiaodu
s=o
elif c<=270:
jiaodu1=jiaodu+180
s=o+math.pi
elif c<=360:
jiaodu1=360+jiaodu
s=2*math.pi+o
op = abs(r* math.sin(a2 + s2 - o) / math.sin(a2))
.2f},{:.2f}°)".format(op, jiaodu1)) :
print("6")
elif c == max(a,b,c):
if c-min(a,b)<180:
o = math.atan((math.sin(a2)*math.sin(a1+a2-s1)-math.sin(a2-s2)*math.sin(a1+a2))/(math.cos(a2-s2)*math.sin(a1+a2)-math.sin(a2)*math.cos(a1+a2-s1)))
jiaodu = math.degrees(o)
if c<90:
jiaodu1=jiaodu
s=o
elif c<=270:
jiaodu1=jiaodu+180
s=o+math.pi
elif c<=360:
jiaodu1=360+jiaodu
s=o+2*math.pi
op = r*math.sin(a2+s-s2)/math.sin(a2)
.2f},{:.2f}°)".format(op,jiaodu1)) :
print("7")
elif c-min(a,b)>180 and c-max(a,b)<180:
o = math.atan((math.sin(a1)*math.sin(a2+s2)-math.sin(a2)*math.sin(a1-s1))/(math.cos(a1-s1)*math.sin(a2)+math.sin(a1)*math.cos(a2+s2)))
jiaodu = math.degrees(o)
print(jiaodu)
if c<90:
jiaodu1=jiaodu
s=o
elif c<=270:
jiaodu1=jiaodu+180
s=o+math.pi
elif c<=360:
jiaodu1=360+jiaodu
s=2*math.pi+o
op =abs( r*math.sin(a1- s1 + s) / math.sin(a1))
.2f},{:.2f}°)".format(op, jiaodu1)) :
print("8")
elif c-max(a,b)>180 :
o = math.atan((math.sin(a1)*math.sin(a2+a1+s2)-math.sin(a1+a2)*math.sin(a1+s1))/(math.sin(a1)*math.cos(a1+a2+s2)-math.sin(a1+a2)*math.cos(a1+s1)))
jiaodu = math.degrees(o)
if c<90:
jiaodu1=jiaodu
s=o
elif c<=270:
jiaodu1=jiaodu+180
s=o+math.pi
elif c<=360:
jiaodu1=360+jiaodu
s=2*math.pi+o
op = abs( r*math.sin( s-a1-s1 )/ math.sin(a1))
.2f},{:.2f}°)".format(op, jiaodu1)) :
print("9")
continue
第三问代码
import math
import numpy as np
import re
l=0
def jiaoduqueding(xunhuancishu,jiaodu,o):
if 1 <= xunhuancishu - 1 <= 3:
if jiaodu > 0:
jiaodu1 = jiaodu
s = o
else:
jiaodu1 = 360 + jiaodu
s = 2 * math.pi + o
elif 4 <= xunhuancishu - 1 <= 5:
if jiaodu > 0:
jiaodu1 = jiaodu
s = o
else:
jiaodu1 = jiaodu + 180
s = o + math.pi
elif 6 <= xunhuancishu - 1 <= 7:
if jiaodu > 0:
jiaodu1 = jiaodu + 180
s = math.pi + o
else:
jiaodu1 = 360 + jiaodu
s = 2 * math.pi + o
elif 8 <= xunhuancishu - 1 <= 9:
if jiaodu > 0:
jiaodu1 = jiaodu + 180
s = math.pi + o
else:
jiaodu1 = 360 + jiaodu
s = 2 * math.pi + o
return jiaodu1,s
list_bianhao=['(0,0)','(100,0)', '(100,40)', '(100,80)', '(100,120)', '(100,160)', '(100,200)', '(100,240)', '(100,280)', '(100,320)']
list_shiji1=['(0,0)','(100,0)','(98,40.10)','(112,80.21)','(105,119.75)','(98,159.86)','(112,199.96)','(105,240.07)','(98,280.17)','(112,320.28)',]
while 1:
q=0
n=0
list1=[]
for i in list_bianhao:
q=q+1
for j in list_shiji1:
if n==q-1 :
list_bianhao[n] =
result = re.findall(r"\((.*?)\)", 理想位置)
lisA = result[0]
lisB = lisA.split(",")
jiaodu1 = float(lisB[1])
a = math.radians(jiaodu1)# 理想的角度
r1 = float(lisB[0]) # 理想的半径
list_shiji1[n] =
result = re.findall(r"\((.*?)\)", 实际位置)
lisA = result[0]
lisB = lisA.split(",")
jiaodu2 = float(lisB[1]) # 实际的角度
b = math.radians(jiaodu2)
r2 = float(lisB[0]) #实际的半经
jiao_du_pian_cha= jiaodu1-jiaodu2 #实际与理想偏差的角度
if -1<jiao_du_pian_cha<1:
jiao_du_pian_cha=jiao_du_pian_cha
else :
jiao_du_pian_cha=360-abs(jiao_du_pian_cha)
c=math.radians(jiao_du_pian_cha) #将角度转化为弧度数
r=r1-r2 #实际与理想半径差
h = abs(c)*r1#这是计算的第n架飞机的弧度长
juli=math.sqrt(h**2+r**2)
list1.append(juli)
n=n+1
else :
continue
A=sum(list1)
print("第{}次调整后每架飞机距离理想位置差值总和为{}".format(l,A))
l=l+1
w=0
fa_she_fei_ji_bian_hao=[]
w=0
f=0
fa_she_fei_ji_bian_hao=[1,2]
list2=sorted(list1)
for i in list1:
w=w+1
if i==list2[2]:
print("误差最小飞机的编号为FY00,FY01,FY0{}".format(w-1))
fa_she_fei_ji_bian_hao.append(w)
else :
continue
print("第{}次调整方向以FY00、FY01、FY0{}这三架无人接为发射无人机。".format(l,fa_she_fei_ji_bian_hao[2]-1))
list_shiji1[1] =
result = re.findall(r"\((.*?)\)",第一架飞机极坐标为)
lisA = result[0]
lisB = lisA.split(",")
a = float(lisB[1])#第一架发射飞机的角度
banjing = float(lisB[0])
s2=math.radians(a)
list_shiji1[fa_she_fei_ji_bian_hao[2]-1] =
result = re.findall(r"\((.*?)\)", 第二架飞机极坐标为)
lisA = result[0]
lisB = lisA.split(",")
b = float(lisB[1])#第二架发射飞机的角度
s1=math.radians(b)
xunhuancishu=0
for i in list_bianhao:
xunhuancishu=xunhuancishu+1
if xunhuancishu==1 or xunhuancishu==fa_she_fei_ji_bian_hao[1] or xunhuancishu==fa_she_fei_ji_bian_hao[2] :
continue
elif xunhuancishu<fa_she_fei_ji_bian_hao[1]:
if fa_she_fei_ji_bian_hao[1]-xunhuancishu<5:#第一类第一种
n1=(180-((fa_she_fei_ji_bian_hao[2]-xunhuancishu)*40))/2
a1=math.radians(n1)
n2=(180-((fa_she_fei_ji_bian_hao[1]-xunhuancishu)*40))/2-n1
a2=math.radians(n2)
o = math.atan((math.sin(a1)*math.sin(a1+a2+s2)-math.sin(a1+s1)*math.sin(a1+a2))/(math.sin(a1)*math.cos(a2+a1+s2)-math.cos(a1+s1)*math.sin(a2+a1)))
jiaodu = math.degrees(o)
result=jiaoduqueding(xunhuancishu,jiaodu,o)
jiaodu1=result[0]
s=result[1]
op = abs(banjing*math.sin(a1+s1-s)/math.sin(a1))
'({:.4f},{:.4f})'.format(op,jiaodu1) =
elif fa_she_fei_ji_bian_hao[1]-xunhuancishu>=5 and fa_she_fei_ji_bian_hao[1]-xunhuancishu<5:#第一类第二种
n1 = (((fa_she_fei_ji_bian_hao[2] - xunhuancishu) * 40)-180) / 2
a1 = math.radians(n1)
n2 = (180 - ((fa_she_fei_ji_bian_hao[1] - xunhuancishu) * 40)) / 2
a2 = math.radians(n2)
o = math.atan((-math.sin(a2) * math.sin(a1-s1)+math.sin(a1)*math.sin(a2+s2)) / (math.sin(a1) * math.cos(a2 + s2) + math.cos(a1 - s1) * math.sin(a2)))
jiaodu = math.degrees(o)
result = jiaoduqueding(xunhuancishu, jiaodu, o)
jiaodu1 = result[0]
s = result[1]
op = abs(banjing * math.sin(a2 + s2 - s)/ math.sin(a2))
'({:.4f},{:.4f})'.format(op,jiaodu1) =
elif fa_she_fei_ji_bian_hao[1] - xunhuancishu > 5:#第一类第三种
n2 = (((fa_she_fei_ji_bian_hao[1] - xunhuancishu) * 40)-180) / 2
a2 = math.radians(n2)
n1 = (((fa_she_fei_ji_bian_hao[2] - xunhuancishu) * 40) - 180) / 2-n2
a1 = math.radians(n1)
o = math.atan((math.sin(a2) * math.sin(a1 + a2 - s1) - math.sin(a1 + a2) * math.sin(a2 - s2)) / (math.sin(a1+a2) * math.cos(a2 - s2) - math.cos(a1 + a2 - s1) * math.sin(a2)))
jiaodu = math.degrees(o)
result = jiaoduqueding(xunhuancishu, jiaodu, o)
jiaodu1 = result[0]
s = result[1]
op = abs(banjing * math.sin(a2 + s -s2)/ math.sin(a2))
'({:.4f},{:.4f})'.format(op,jiaodu1) =
elif fa_she_fei_ji_bian_hao[1]<xunhuancishu<fa_she_fei_ji_bian_hao[2]:
if fa_she_fei_ji_bian_hao[2]-xunhuancishu<5 and xunhuancishu-fa_she_fei_ji_bian_hao[1]<5:#第二类第一种
n1=abs(180-(abs(fa_she_fei_ji_bian_hao[2]-xunhuancishu)*40))/2
a1=math.radians(n1)
n2=abs(180-(abs(xunhuancishu-fa_she_fei_ji_bian_hao[1])*40))/2
a2=math.radians(n2)
o = math.atan((-math.sin(a1)*math.sin(a2-s2)+math.sin(a2)*math.sin(a1+s1))/(math.sin(a2)*math.cos(a1+s1)+math.sin(a1)*math.cos(a2-s2)))
jiaodu = math.degrees(o)
result = jiaoduqueding(xunhuancishu, jiaodu, o)
jiaodu1 = result[0]
s = result[1]
op = abs(banjing * math.sin(a1 + s1 - s) / math.sin(a1))
'({:.4f},{:.4f})'.format(op,jiaodu1) =
elif fa_she_fei_ji_bian_hao[2]-xunhuancishu>=5 and xunhuancishu-fa_she_fei_ji_bian_hao[1]<5:#第二类第二种
n1 = (((fa_she_fei_ji_bian_hao[2] - xunhuancishu) * 40)-180) / 2
a1 = math.radians(n1)
n2 = (180-((xunhuancishu - fa_she_fei_ji_bian_hao[1]) * 40)) / 2
a2 = math.radians(n2)
o = math.atan((math.sin(a1)*math.sin(a1+a2-s2)-math.sin(a1-s1)*math.sin(a1+a2)) / (math.sin(a1+a2) * math.cos(a1-s1)-math.sin(a1)*math.cos(a1+a2-s2)))
jiaodu = math.degrees(o)
result = jiaoduqueding(xunhuancishu, jiaodu, o)
jiaodu1 = result[0]
s = result[1]
op = abs(banjing * math.sin(a1 - s1 + s) / math.sin(a1))
'({:.4f},{:.4f})'.format(op,jiaodu1) =
elif fa_she_fei_ji_bian_hao[2]-xunhuancishu<5 and xunhuancishu-fa_she_fei_ji_bian_hao[1]>=5:#第二类第三种
n1 = abs(abs((fa_she_fei_ji_bian_hao[2] - xunhuancishu) * 40)-180) / 2
a2 = math.radians(n1)
n2 = abs(180 - (abs(xunhuancishu - fa_she_fei_ji_bian_hao[1]) * 40)) / 2-n1
a1 = math.radians(n2)
o = math.atan((math.sin(a1)*math.sin(a1+a2-s2)-math.sin(a1-s1)*math.sin(a1+a2)) / (math.sin(a1+a2) * math.cos(a1-s1)-math.sin(a1)*math.cos(a1+a2-s2)))
jiaodu = math.degrees(o)
result = jiaoduqueding(xunhuancishu, jiaodu, o)
jiaodu1 = result[0]
s = result[1]
op = abs(banjing * math.sin(a1 - s1 + s) / math.sin(a1))
'({:.4f},{:.4f})'.format(op,jiaodu1) =
elif xunhuancishu>fa_she_fei_ji_bian_hao[2]:
if abs(fa_she_fei_ji_bian_hao[1]-xunhuancishu)<5:#第三类第一种
n1 = abs(abs((fa_she_fei_ji_bian_hao[1] - xunhuancishu) * 40)-180) / 2
a2 = math.radians(n1)
n2 = abs(180 - (abs(xunhuancishu - fa_she_fei_ji_bian_hao[2]) * 40)) / 2-n1
a1 = math.radians(n2)
o = math.atan((math.sin(a2)*math.sin(a1+a2-s1)-math.sin(a2-s2)*math.sin(a1+a2))/(math.cos(a2-s2)*math.sin(a1+a2)-math.sin(a2)*math.cos(a1+a2-s1)))
jiaodu = math.degrees(o)
result = jiaoduqueding(xunhuancishu, jiaodu, o)
jiaodu1 = result[0]
s = result[1]
op = abs(banjing*math.sin(a2+s-s2)/math.sin(a2))
'({:.4f},{:.4f})'.format(op,jiaodu1) =
elif abs(fa_she_fei_ji_bian_hao[1]-xunhuancishu)>=5 and abs(fa_she_fei_ji_bian_hao[2]-xunhuancishu)<5:#第三类第二种
n1 = abs(abs((fa_she_fei_ji_bian_hao[2] - xunhuancishu) * 40)-180) / 2
a1 = math.radians(n1)
n2 = abs(180 - abs((xunhuancishu - fa_she_fei_ji_bian_hao[1]) * 40)) / 2
a2 = math.radians(n2)
o = math.atan((math.sin(a1)*math.sin(a2+s2)-math.sin(a2)*math.sin(a1-s1))/(math.cos(a1-s1)*math.sin(a2)+math.sin(a1)*math.cos(a2+s2)))
jiaodu = math.degrees(o)
result = jiaoduqueding(xunhuancishu, jiaodu, o)
jiaodu1 = result[0]
s = result[1]
op =abs( banjing*math.sin(a1- s1 + s) / math.sin(a1))
'({:.4f},{:.4f})'.format(op,jiaodu1) =
elif abs(fa_she_fei_ji_bian_hao[2]-xunhuancishu)>=5:#第三类第三种
n1 = abs(abs((fa_she_fei_ji_bian_hao[2] - xunhuancishu) * 40)-180) / 2
a1 = math.radians(n1)
n2 = abs(180 - (abs(xunhuancishu - fa_she_fei_ji_bian_hao[1]) * 40)) / 2-n1
a2 = math.radians(n2)
o = math.atan((math.sin(a1)*math.sin(a2+a1+s2)-math.sin(a1+a2)*math.sin(a1+s1))/(math.sin(a1)*math.cos(a1+a2+s2)-math.sin(a1+a2)*math.cos(a1+s1)))
jiaodu = math.degrees(o)
result = jiaoduqueding(xunhuancishu, jiaodu, o)
jiaodu1 = result[0]
s = result[1]
op = abs( banjing*math.sin( s-a1-s1 )/ math.sin(a1))
'({:.4f},{:.4f})'.format(op,jiaodu1) =
"") =
print(list_shiji1)
if A<0.01:
break
else :
continue
作者:2023级数学专业学弟,学妹;2022级数学专业学妹(均为本科生)
感谢您的阅读,欢迎指出问题!