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

相关文章

python编写朋克风格的天气查询程序

《python编写朋克风格的天气查询程序》这篇文章主要为大家详细介绍了一个基于Python的桌面应用程序,使用了tkinter库来创建图形用户界面并通过requests库调用Open-MeteoAPI... 目录工具介绍工具使用说明python脚本内容如何运行脚本工具介绍这个天气查询工具是一个基于 Pyt

Ubuntu设置程序开机自启动的操作步骤

《Ubuntu设置程序开机自启动的操作步骤》在部署程序到边缘端时,我们总希望可以通电即启动我们写好的程序,本篇博客用以记录如何在ubuntu开机执行某条命令或者某个可执行程序,需要的朋友可以参考下... 目录1、概述2、图形界面设置3、设置为Systemd服务1、概述测试环境:Ubuntu22.04 带图

Python程序打包exe,单文件和多文件方式

《Python程序打包exe,单文件和多文件方式》:本文主要介绍Python程序打包exe,单文件和多文件方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录python 脚本打成exe文件安装Pyinstaller准备一个ico图标打包方式一(适用于文件较少的程

Python程序的文件头部声明小结

《Python程序的文件头部声明小结》在Python文件的顶部声明编码通常是必须的,尤其是在处理非ASCII字符时,下面就来介绍一下两种头部文件声明,具有一定的参考价值,感兴趣的可以了解一下... 目录一、# coding=utf-8二、#!/usr/bin/env python三、运行Python程序四、

无法启动此程序因为计算机丢失api-ms-win-core-path-l1-1-0.dll修复方案

《无法启动此程序因为计算机丢失api-ms-win-core-path-l1-1-0.dll修复方案》:本文主要介绍了无法启动此程序,详细内容请阅读本文,希望能对你有所帮助... 在计算机使用过程中,我们经常会遇到一些错误提示,其中之一就是"api-ms-win-core-path-l1-1-0.dll丢失

SpringBoot后端实现小程序微信登录功能实现

《SpringBoot后端实现小程序微信登录功能实现》微信小程序登录是开发者通过微信提供的身份验证机制,获取用户唯一标识(openid)和会话密钥(session_key)的过程,这篇文章给大家介绍S... 目录SpringBoot实现微信小程序登录简介SpringBoot后端实现微信登录SpringBoo

uniapp小程序中实现无缝衔接滚动效果代码示例

《uniapp小程序中实现无缝衔接滚动效果代码示例》:本文主要介绍uniapp小程序中实现无缝衔接滚动效果的相关资料,该方法可以实现滚动内容中字的不同的颜色更改,并且可以根据需要进行艺术化更改和自... 组件滚动通知只能实现简单的滚动效果,不能实现滚动内容中的字进行不同颜色的更改,下面实现一个无缝衔接的滚动

Java使用WebView实现桌面程序的技术指南

《Java使用WebView实现桌面程序的技术指南》在现代软件开发中,许多应用需要在桌面程序中嵌入Web页面,例如,你可能需要在Java桌面应用中嵌入一部分Web前端,或者加载一个HTML5界面以增强... 目录1、简述2、WebView 特点3、搭建 WebView 示例3.1 添加 JavaFX 依赖3

防止SpringBoot程序崩溃的几种方式汇总

《防止SpringBoot程序崩溃的几种方式汇总》本文总结了8种防止SpringBoot程序崩溃的方法,包括全局异常处理、try-catch、断路器、资源限制、监控、优雅停机、健康检查和数据库连接池配... 目录1. 全局异常处理2. 使用 try-catch 捕获异常3. 使用断路器4. 设置最大内存和线

使用Python创建一个功能完整的Windows风格计算器程序

《使用Python创建一个功能完整的Windows风格计算器程序》:本文主要介绍如何使用Python和Tkinter创建一个功能完整的Windows风格计算器程序,包括基本运算、高级科学计算(如三... 目录python实现Windows系统计算器程序(含高级功能)1. 使用Tkinter实现基础计算器2.