python - 根据应用于源数组的公式创建数组
问题描述
我正在尝试将四个公式应用于数组中的一组坐标,以生成两个额外的数组,然后我可以绘制它们。
这两个新数组称为“internal_edge”和“external_edge”。
在下面的代码中,我打印了需要应用于“internal_edge”和“external_edge”的 X 和 Y 的四个方程。
import numpy as np
import math as m
from matplotlib import pyplot as plt
track_width = 0.25
centre_line = np.array([
[5.2838386568469105, 0.5533114231405133],[5.366471208948866, 0.5138588293370626],[5.449968630730311, 0.47627584038467463],[5.534812288152224, 0.4418872118882958],[5.621950766713397, 0.4139674411266211],[5.711536576482786, 0.3955402988007556],[5.80273779150609, 0.38945006681201744],[5.893859166442468, 0.3968403768909704],[5.983006824666859, 0.41711137467093196],
])
x1, y1 = centre_line.T
#Internal X[0] Value:
print(track_width*m.cos(m.radians(m.degrees(m.atan2(y1[1]-y1[0],x1[1]-x1[0]))+90))+x1[1])
#Internal Y[0] Value:
print(track_width*m.sin(m.radians(m.degrees(m.atan2(y1[1]-y1[0],x1[1]-x1[0]))+90))+y1[1])
#External X[0] Value:
print(track_width*m.cos(m.radians(m.degrees(m.atan2(y1[1]-y1[0],x1[1]-x1[0]))-90))+x1[1])
#External Y[0] Value:
print(track_width*m.sin(m.radians(m.degrees(m.atan2(y1[1]-y1[0],x1[1]-x1[0]))-90))+y1[1])
internal_edge = np.array([
])
external_edge = np.array([
])
x2, y2 = internal_edge.T
x3, y3 = external_edge.T
plt.scatter(x1,y1,color='blue')
plt.scatter(x2,y2,color='green')
plt.scatter(x3,y3,color='red')
plt.show()
我现在需要弄清楚如何将这些应用到我的数组中的每个数据点以生成我的新数组。
解决方案
这是你如何做到的。
import numpy as np
from matplotlib import pyplot as plt
track_width = 0.25
centre_line = np.array([
[5.2838386568469105, 0.5533114231405133],[5.366471208948866, 0.5138588293370626],[5.449968630730311, 0.47627584038467463],[5.534812288152224, 0.4418872118882958],[5.621950766713397, 0.4139674411266211],[5.711536576482786, 0.3955402988007556],[5.80273779150609, 0.38945006681201744],[5.893859166442468, 0.3968403768909704],[5.983006824666859, 0.41711137467093196],
])
x1, y1 = centre_line.T
# adjust for full dataset maybe?
x1 = np.append(x1, x1[0])
y1 = np.append(y1, y1[0])
angle = np.arctan2(y1[1:] - y1[:-1], x1[1:] - x1[:-1])
internal_edge = np.array([
track_width*np.cos(angle + np.deg2rad(90)) + x1[1:],
track_width*np.sin(angle + np.deg2rad(90)) + y1[1:],
])
external_edge = np.array([
track_width*np.cos(angle - np.deg2rad(90)) + x1[1:],
track_width*np.sin(angle - np.deg2rad(90)) + y1[1:],
])
x2, y2 = internal_edge
x3, y3 = external_edge
plt.scatter(x1,y1,color='blue')
plt.scatter(x2,y2,color='green')
plt.scatter(x3,y3,color='red')
plt.show()
推荐阅读
- java - 数据绑定没有在android中将数据与xml绑定
- php - 如何解决codeigniter中的Access-control-Allow_origin
- c - 如何打印出一对以上的素数
- java - Java 是否忽略了我的 -Xmx 和 -Xms 参数?
- mysql - 如何从nodejs中的嵌套函数返回db的结果
- javascript - jQuery 验证不适用于焦点输出?
- embedded - 如何将 .ino 文件转换为 .bin 文件,从 arduinoIDE 使用“草图 + WiFi 设置”通过“ESP8266 下载工具”上传到 S3 ESP8266?
- javascript - 在现有项目中使用 Vue.js 和 ReactiveSearch
- jmeter - jmeter中的长时间浸泡测试
- typescript - 使用 UMD 构建时如何使用带有类型定义的 RxJS?