资源简介
仿真3D版本.py
代码片段和文件信息
import time
import copy
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import animation
from mpl_toolkits.mplot3d import Axes3D
NUM = 10
n = np.random.randint(310) # 3、4、5边形
R = 30 # 多边形半径
Point_List = []
‘‘‘高度错开所需参数‘‘‘
low SPEED0 Hight = 0 2 200
distance = 380 / NUM
‘‘‘抵达边界所需参数 # 根据无人机数量NUM得出边界最大容量数量MAXNUM‘‘‘
MOVE_DISTANCE = 0.3
JianCeError = 0.1
if ((NUM - n) / n) % 1 == 0:
MAXNUM = (NUM - n) / n
else:
MAXNUM = int((NUM - n) / n) + 1
JIANJU = 2 * R * np.sin(np.pi / n) / (MAXNUM + 1)
# 2 * R * np.sin(np.pi/n)是边界长度, JIANJU是调整单位距离
‘‘‘均匀化参数‘‘‘
Ting_Distance = 3
Move_Distance = 20 # 20 * 0.01 =0.2
‘‘‘随机生成初始分布位置 设定多边形位置 ‘‘‘
x = np.random.randint(1 100 NUM)
y = np.random.randint(1 100 NUM)
z = [0 for i in range(NUM)]
for i in range(NUM):
Point_List.append([x[i] y[i] z[i]])
# 多边形数量设定
DING_LIST = []
DingX DingY DingZ = [] [] []
def PolygonInit():
global DING_LIST
global n
global DingX DingY DingZ
for i in range(1 n + 1):
x = 50 + R * np.sin(i * 2 * np.pi / n)
y = 50 + R * np.cos(i * 2 * np.pi / n)
DING_LIST.append([x y Hight])
DingX DingY DingZ = [] [] []
for each in DING_LIST:
DingX.append(each[0])
DingY.append(each[1])
DingZ.append(each[2])
DingX.append(DING_LIST[0][0])
DingY.append(DING_LIST[0][1])
DingZ.append(DING_LIST[0][2])
PolygonInit() # 初始化多边形顶点位置
‘‘‘初始化图像‘‘‘
fig = plt.figure()
ax = plt.gca(projection=‘3d‘)
ax.set_xlim(0 100)
ax.set_xlabel(‘X‘)
ax.set_ylim(0 100)
ax.set_ylabel(‘Y‘)
ax.set_zlim(0 400)
ax.set_zlabel(‘Z‘)
sc = ax.scatter3D(x y z color=‘r‘ alpha=0.7)
# ax.plot(DingX DingY DingZ ‘b:‘)
#sc = ax.scatter3D(x yz color=‘r‘ alpha=0.7marker=‘1‘linewidth = 8)
ax.plot(DingX DingYDingZ color = ‘black‘linestyle = ‘:‘)
D = 2 * R * np.sin(np.pi / n)
num = int(D / 0.01)
tooth_distance = D / num
Tooth_Chain = []
def Chain_make():
global Tooth_Chain
for i in range(0 n):
Tooth_Chain.append(DING_LIST[i])
base_pos = copy.deepcopy(DING_LIST[i])
if i == len(DING_LIST) - 1:
next = DING_LIST[0]
else:
next = DING_LIST[i + 1]
x = np.array([next[0] - DING_LIST[i][0] next[1] - DING_LIST[i][1]]) # 方向向量
y = np.array([1 0]) # x轴方向
Lx = np.sqrt(x.dot(x)) # x.dot(x) 点乘自己,相当于向量模平方
Ly = np.sqrt(y.dot(y))
cos_angle = x.dot(y) / (Lx * Ly)
angle = np.arccos(cos_angle)
if x[0] >= 0 and x[1] >= 0:
for j in range(1 num):
a = base_pos[0] + j * tooth_distance * abs(np.cos(angle))
b = base_pos[1] + j * tooth_distance * abs(np.sin(angle))
Tooth_Chain.append([a b Hight])
# print(‘1‘ len(Tooth_Chain))
elif x[0] <= 0 and x[1] >= 0:
for j in range(1 num):
a = base_pos[
相关资源
- Python零基础10天进阶班.rar
- 用Python自动办公,做职场高手.txt
- 基于python实现的http接口自动化测试框
- spider_LOL.py
- Python教程.rar
- 小甲鱼零基础入门学习Python视频教程
- 麦子学院Python全套视频.txt
- 《疯狂Python讲义》习题答案.rar
- publishHelper.py
- sendInfo.py
- Python零基础10天进阶班.docx
- Python数据科学指南_Code.zip
- 爬取URP教务网站学籍信息.py
- Anaconda历史版本Python3.6版本.zip
- car_detected.py
- Python-图像分割Keras在Keras中实现Segne
评论
共有 条评论