20240219画图程序

2024-02-19 21:20
文章标签 程序 画图 20240219

本文主要是介绍20240219画图程序,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1. PTZ在惯性态时,不同视场角下的【发送】角速度和【理论响应】角速度

1.1 优化前

请添加图片描述

import numpy as np
import matplotlib.pyplot as plt# PTZ在惯性态时,不同视场角下的【发送】角速度和【理论响应】角速度
ATROffset_x = np.linspace(0, 60, 120)
y2 = ATROffset_x * 2 / 28
y4 = ATROffset_x * 4 / 28
y6 = ATROffset_x * 6 / 28
y8 = ATROffset_x * 8 / 28
y10 = ATROffset_x * 10 / 28
y12 = ATROffset_x * 12 / 28
y14 = ATROffset_x * 14 / 28
y16 = ATROffset_x * 16 / 28
y18 = ATROffset_x * 18 / 28
y20 = ATROffset_x * 20 / 28
y22 = ATROffset_x * 22 / 28
y24 = ATROffset_x * 24 / 28
y26 = ATROffset_x * 26 / 28
y28 = ATROffset_x * 28 / 28plt.plot(ATROffset_x, y2, label='field angle: 2 degrees')
plt.plot(ATROffset_x, y4, linestyle='dotted',label='field angle: 4 degrees')
plt.plot(ATROffset_x, y6, linestyle='--',label='field angle: 6 degrees')
plt.plot(ATROffset_x, y8, linestyle='-.', label='field angle: 8 degrees')plt.plot(ATROffset_x, y10, label='field angle: 10 degrees')
plt.plot(ATROffset_x, y12, linestyle='dotted', label='field angle: 12 degrees')
plt.plot(ATROffset_x, y14, linestyle='--',label='field angle: 14 degrees')
plt.plot(ATROffset_x, y16, linestyle='-.', label='field angle: 16 degrees')plt.plot(ATROffset_x, y18, label='field angle: 18 degrees')
plt.plot(ATROffset_x, y20, linestyle='dotted', label='field angle: 20 degrees')
plt.plot(ATROffset_x, y22, linestyle='--',label='field angle: 22 degrees')
plt.plot(ATROffset_x, y24, linestyle='-.', label='field angle: 24 degrees')plt.plot(ATROffset_x, y26, linestyle='dotted', label='field angle: 26 degrees')
plt.plot(ATROffset_x, y28, label='field angle: 28 degrees')plt.xlabel('sending value[degree/second]')
plt.ylabel('thertical response[degree/second]')
plt.title('PTZ angular velocity: sending value & thertical response')
handles, labels = plt.gca().get_legend_handles_labels()
# plt.legend(handles[::-1], labels[::-1],loc='right')
plt.legend(handles[::-1], labels[::-1])
plt.grid()
plt.show()

1.2 优化后

请添加图片描述

import numpy as np
import matplotlib.pyplot as pltATROffset_x = np.linspace(0, 60, 120)
linestyles = ['-', 'dotted', '--', '-.', '-', 'dotted', '--', '-.', '-', 'dotted', '--', '-.', '-', 'dotted']
labels = [f'field angle: {i} degrees' for i in range(2, 30, 2)]for i, linestyle in enumerate(linestyles):y = ATROffset_x * (i + 2) / 28plt.plot(ATROffset_x, y, linestyle=linestyle, label=labels[i])plt.xlabel('sending value[degree/second]')
plt.ylabel('thertical response[degree/second]')
plt.title('PTZ angular velocity: sending value & thertical response')
handles, labels = plt.gca().get_legend_handles_labels()
plt.legend(handles[::-1], labels[::-1])
plt.grid()
plt.show()

2. 像素偏移与发送角速度

请添加图片描述

import numpy as np
import matplotlib.pyplot as plt# 分段函数
def piecewise_function(x):if x >80: return x/9elif x>30: return x/4elif x>10: return x/1.8elif x>3: return x/1.8elif x>1: return xelse: return 0# 生成x值
x = np.linspace(0, 512, 2000)
# 计算y值
y1 = [piecewise_function(xi) for xi in x]
y2 = 2.5*(x**(0.5))
# y3 = 2.5*(x**(0.8))points = [(506.25, piecewise_function(506.25))]
for point in points:plt.plot(point[0], point[1], 'ro')plt.annotate(f'({point[0]}, {point[1]:.2f})', (point[0], point[1]), textcoords="offset points", xytext=(0,10), ha='center')# 绘制图形
plt.plot(x, y1, label='piecewise function', linestyle='-.')
plt.plot(x, y2, label='2.5*pow(x,0.5)')
# plt.plot(x, y3, label='x**0.8')plt.xlabel('pixel offset[pixel]')
plt.ylabel('sending value[degree/second]')
plt.title('PTZ angular velocity: sending value & pixel offset')
plt.grid()
plt.legend()
plt.show()

3. 估算不同焦距下的目标大小

3.1 原理

  • 【任务】:已知POD与目标之间的高度差3000m和水平距离2000m,需要解算7m*3m目标在POD观察画面中的大小
  • 【途径】:利用视场角解算视野大小,绘制目标在POD观察画面中的大小
    • 解算视场角大小:
      • fieldAngle_yaw = arctan(5.632/focalDistance)*180/Pi
      • fieldAngle_pitch = arctan(4.224/focalDistance)*180/Pi
    • 解算POD与目标的直线距离distance
    • 解算视野覆盖的实际长和宽
      • fieldWidth = 2*tan(fieldAngle_yaw/2)/disctance
      • fieldWidth = 2*tan(fieldAngle_pitch/2)/disctance
    • 解算目标在视野中的比例后,可得3.2中的图像

请添加图片描述

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D# 参数方程定义的单位球面
def sphere(u, v):theta = u * 2 * np.piphi = v * np.pix = np.sin(phi) * np.cos(theta)y = np.sin(phi) * np.sin(theta)z = np.cos(phi)return x, y, zdef plot_rectangle_tangent_to_point(point):# 计算点到原点的单位向量point_normalized = point / np.linalg.norm(point)# 找到一个与点到原点的向量垂直的向量perpendicular_vector_1 = np.cross(point_normalized, [1, 0, 0])if np.allclose(perpendicular_vector_1, [0, 0, 0]):# 如果点到原点的向量与[1, 0, 0]平行,则选择[0, 1, 0]作为第二个向量perpendicular_vector_1 = np.cross(point_normalized, [0, 1, 0])perpendicular_vector_1 /= np.linalg.norm(perpendicular_vector_1)# 找到与第一个向量垂直的第二个向量perpendicular_vector_2 = np.cross(point_normalized, perpendicular_vector_1)perpendicular_vector_2 /= np.linalg.norm(perpendicular_vector_2)# 生成矩形的四个顶点rectangle_half_side = 0.5  # 矩形边长的一半rectangle_vertices = np.array([point_normalized + rectangle_half_side * perpendicular_vector_1 + rectangle_half_side * perpendicular_vector_2,point_normalized - rectangle_half_side * perpendicular_vector_1 + rectangle_half_side * perpendicular_vector_2,point_normalized - rectangle_half_side * perpendicular_vector_1 - rectangle_half_side * perpendicular_vector_2,point_normalized + rectangle_half_side * perpendicular_vector_1 - rectangle_half_side * perpendicular_vector_2,point_normalized + rectangle_half_side * perpendicular_vector_1 + rectangle_half_side * perpendicular_vector_2  # 重复第一个点以闭合图形])# 绘制矩形切面fig = plt.figure(figsize=(10, 10))ax = fig.add_subplot(111, projection='3d')ax.plot(rectangle_vertices[:, 0], rectangle_vertices[:, 1], rectangle_vertices[:, 2], color='r')ax.scatter(point[0], point[1], point[2], color='b', s=50)  # 绘制点# 定义两个点point1 = pointpoint2 = np.array([0, 0, 0])# 绘制两个点ax.scatter(point1[0], point1[1], point1[2], color='r', s=100)ax.scatter(point2[0], point2[1], point2[2], color='b', s=100)# 绘制连线ax.plot([point1[0], point2[0]], [point1[1], point2[1]], [point1[2], point2[2]], color='k', linestyle='--')# 绘制中点fyo = (point_normalized + rectangle_half_side * perpendicular_vector_1 + rectangle_half_side * perpendicular_vector_2 + point_normalized + rectangle_half_side * perpendicular_vector_1 - rectangle_half_side * perpendicular_vector_2)/2ax.scatter(fyo[0], fyo[1], fyo[2], color='b', s=50)  # 绘制点# 绘制连线ax.plot([fyo[0], point2[0]], [fyo[1], point2[1]], [fyo[2], point2[2]], color='k', linestyle='--')# 绘制连线-平面内ax.plot([fyo[0], point[0]], [fyo[1], point[1]], [fyo[2], point[2]], color='k', linestyle='--')# 创建参数u = np.linspace(0, 2, 100)v = np.linspace(0, 2, 100)u, v = np.meshgrid(u, v)# 计算球面上的点x, y, z = sphere(u, v)# 绘制单位球面ax.plot_surface(x, y, z, color='b', alpha=0.02)# 画出xyz轴ax.plot([0, 1], [0, 0], [0, 0], color='red', linestyle='-', linewidth=2)ax.plot([0, 0], [0, 1], [0, 0], color='green', linestyle='-', linewidth=2)ax.plot([0, 0], [0, 0], [0, 1], color='blue', linestyle='-', linewidth=2)# 设置坐标轴等比例ax.set_box_aspect([1,1,1])# 设置坐标轴标签ax.set_xlabel('X')ax.set_ylabel('Y')ax.set_zlabel('Z')# 设置x轴的刻度ax.set_xticks([-1, -0.5, 0, 0.5, 1])# 设置y轴的刻度ax.set_yticks([-1, -0.5, 0, 0.5, 1])# 设置z轴的刻度ax.set_zticks([-1, -0.5, 0, 0.5, 1])# 设置标题plt.title("Since: tan(fieldAngle/2) = (fieldWidth/2) / distance\n\nThen: fieldWidth = 2 * tan(fieldAngle/2) * distance")plt.show()point_on_sphere = np.array([-0.55, 0, -0.83])
plot_rectangle_tangent_to_point(point_on_sphere)

3.2 绘图

  • POD与目标之间高度差3000m、水平距离2000m,目标尺寸7m*3m
  • 不同焦距下,该目标在POD观察画面中的大小如图所示请添加图片描述
import matplotlib.pyplot as plt
import matplotlib.patches as patches
import numpy as np
import mathrelative_target_height = 3000
relative_target_horizontal = 2000
relative_distance = math.sqrt(relative_target_height*relative_target_height + relative_target_horizontal*relative_target_horizontal)
print("relative_distance: ", relative_distance)fig, ax = plt.subplots()# 创建一个新的图形
plt.title("ROI SIZE of 7m*3m target: 3000m high & 2000m distance")# 设置标题def fd2pic(fd):horizontal_draw = np.tan(math.atan(5.632/fd)/2) * relative_distance * 2vertical_draw = np.tan(math.atan(4.224/fd)/2) * relative_distance * 2# 添加第一个框rect = patches.Rectangle((6*7/horizontal_draw*1024, 14*3/vertical_draw*768), 7/horizontal_draw*1024, 3/vertical_draw*768, linewidth=1, edgecolor='r', facecolor='none')ax.add_patch(rect)# 在第一个框旁边打印文字ax.text(7*7/horizontal_draw*1024+20, 14*3/vertical_draw*768, "fd: {:.2f}".format(fd), fontsize=12, color='r')for i in range(9):fd2pic(max(40*i,10.59))plt.xlim(0, 1024)
plt.ylim(0, 768)
plt.xticks([0, 1024])
plt.yticks([0, 768])
plt.show()

这篇关于20240219画图程序的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/726016

相关文章

将java程序打包成可执行文件的实现方式

《将java程序打包成可执行文件的实现方式》本文介绍了将Java程序打包成可执行文件的三种方法:手动打包(将编译后的代码及JRE运行环境一起打包),使用第三方打包工具(如Launch4j)和JDK自带... 目录1.问题提出2.如何将Java程序打包成可执行文件2.1将编译后的代码及jre运行环境一起打包2

在不同系统间迁移Python程序的方法与教程

《在不同系统间迁移Python程序的方法与教程》本文介绍了几种将Windows上编写的Python程序迁移到Linux服务器上的方法,包括使用虚拟环境和依赖冻结、容器化技术(如Docker)、使用An... 目录使用虚拟环境和依赖冻结1. 创建虚拟环境2. 冻结依赖使用容器化技术(如 docker)1. 创

JAVA智听未来一站式有声阅读平台听书系统小程序源码

智听未来,一站式有声阅读平台听书系统 🌟 开篇:遇见未来,从“智听”开始 在这个快节奏的时代,你是否渴望在忙碌的间隙,找到一片属于自己的宁静角落?是否梦想着能随时随地,沉浸在知识的海洋,或是故事的奇幻世界里?今天,就让我带你一起探索“智听未来”——这一站式有声阅读平台听书系统,它正悄悄改变着我们的阅读方式,让未来触手可及! 📚 第一站:海量资源,应有尽有 走进“智听

EMLOG程序单页友链和标签增加美化

单页友联效果图: 标签页面效果图: 源码介绍 EMLOG单页友情链接和TAG标签,友链单页文件代码main{width: 58%;是设置宽度 自己把设置成与您的网站宽度一样,如果自适应就填写100%,TAG文件不用修改 安装方法:把Links.php和tag.php上传到网站根目录即可,访问 域名/Links.php、域名/tag.php 所有模板适用,代码就不粘贴出来,已经打

跨系统环境下LabVIEW程序稳定运行

在LabVIEW开发中,不同电脑的配置和操作系统(如Win11与Win7)可能对程序的稳定运行产生影响。为了确保程序在不同平台上都能正常且稳定运行,需要从兼容性、驱动、以及性能优化等多个方面入手。本文将详细介绍如何在不同系统环境下,使LabVIEW开发的程序保持稳定运行的有效策略。 LabVIEW版本兼容性 LabVIEW各版本对不同操作系统的支持存在差异。因此,在开发程序时,尽量使用

CSP 2023 提高级第一轮 CSP-S 2023初试题 完善程序第二题解析 未完

一、题目阅读 (最大值之和)给定整数序列 a0,⋯,an−1,求该序列所有非空连续子序列的最大值之和。上述参数满足 1≤n≤105 和 1≤ai≤108。 一个序列的非空连续子序列可以用两个下标 ll 和 rr(其中0≤l≤r<n0≤l≤r<n)表示,对应的序列为 al,al+1,⋯,ar​。两个非空连续子序列不同,当且仅当下标不同。 例如,当原序列为 [1,2,1,2] 时,要计算子序列 [

这些心智程序你安装了吗?

原文题目:《为什么聪明人也会做蠢事(四)》 心智程序 大脑有两个特征导致人类不够理性,一个是处理信息方面的缺陷,一个是心智程序出了问题。前者可以称为“认知吝啬鬼”,前几篇文章已经讨论了。本期主要讲心智程序这个方面。 心智程序这一概念由哈佛大学认知科学家大卫•帕金斯提出,指个体可以从记忆中提取出的规则、知识、程序和策略,以辅助我们决策判断和解决问题。如果把人脑比喻成计算机,那心智程序就是人脑的

uniapp设置微信小程序的交互反馈

链接:uni.showToast(OBJECT) | uni-app官网 (dcloud.net.cn) 设置操作成功的弹窗: title是我们弹窗提示的文字 showToast是我们在加载的时候进入就会弹出的提示。 2.设置失败的提示窗口和标签 icon:'error'是设置我们失败的logo 设置的文字上限是7个文字,如果需要设置的提示文字过长就需要设置icon并给

基于SpringBoot的宠物服务系统+uniapp小程序+LW参考示例

系列文章目录 1.基于SSM的洗衣房管理系统+原生微信小程序+LW参考示例 2.基于SpringBoot的宠物摄影网站管理系统+LW参考示例 3.基于SpringBoot+Vue的企业人事管理系统+LW参考示例 4.基于SSM的高校实验室管理系统+LW参考示例 5.基于SpringBoot的二手数码回收系统+原生微信小程序+LW参考示例 6.基于SSM的民宿预订管理系统+LW参考示例 7.基于

Spring Roo 实站( 一 )部署安装 第一个示例程序

转自:http://blog.csdn.net/jun55xiu/article/details/9380213 一:安装 注:可以参与官网spring-roo: static.springsource.org/spring-roo/reference/html/intro.html#intro-exploring-sampleROO_OPTS http://stati