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程序打包成EXE文件的实现方式

《将Java程序打包成EXE文件的实现方式》:本文主要介绍将Java程序打包成EXE文件的实现方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录如何将Java程序编程打包成EXE文件1.准备Java程序2.生成JAR包3.选择并安装打包工具4.配置Launch4

Java程序进程起来了但是不打印日志的原因分析

《Java程序进程起来了但是不打印日志的原因分析》:本文主要介绍Java程序进程起来了但是不打印日志的原因分析,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录Java程序进程起来了但是不打印日志的原因1、日志配置问题2、日志文件权限问题3、日志文件路径问题4、程序

SpringBoot实现微信小程序支付功能

《SpringBoot实现微信小程序支付功能》小程序支付功能已成为众多应用的核心需求之一,本文主要介绍了SpringBoot实现微信小程序支付功能,文中通过示例代码介绍的非常详细,对大家的学习或者工作... 目录一、引言二、准备工作(一)微信支付商户平台配置(二)Spring Boot项目搭建(三)配置文件

如何用java对接微信小程序下单后的发货接口

《如何用java对接微信小程序下单后的发货接口》:本文主要介绍在微信小程序后台实现发货通知的步骤,包括获取Access_token、使用RestTemplate调用发货接口、处理AccessTok... 目录配置参数 调用代码获取Access_token调用发货的接口类注意点总结配置参数 首先需要获取Ac

基于Python开发PDF转Doc格式小程序

《基于Python开发PDF转Doc格式小程序》这篇文章主要为大家详细介绍了如何基于Python开发PDF转Doc格式小程序,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 用python实现PDF转Doc格式小程序以下是一个使用Python实现PDF转DOC格式的GUI程序,采用T

将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各版本对不同操作系统的支持存在差异。因此,在开发程序时,尽量使用