抛物线中间
我正在编写一个代码来绘制辊轮廓。滚子的半径可能有所不同,我想获得的轮廓是凹面抛物线。要求是我应该能够在它们之间生成带有不同辐射和不同类似抛物线的结构的随机辊轮廓。以下是我编写的示例代码,但希望它更通用,并且还希望在Python中使用随机功能来生成随机轮廓。
有人可以帮忙吗?我需要在线段之间生成n个具有不同辐射和不同抛物线形状的滚筒数。同样,抛物线不必总是躺在y = 0上。它应该能够左右移动。
import matplotlib.pyplot as plt
import numpy as np
import random
def rec():
x = list(np.arange(-15, 16, 1))
y = [-35, 35]
y0 = []
for xv in x:
p = (xv, y[0])
y0.append(p)
y1 = []
for xv in x:
q = (xv, y[-1])
y1.append(q)
# plt.plot(x_val, y_val)
x_range = [elx[0] for elx in y0]
y_nve = [ely[1] for ely in y0]
# plt.plot(x_val, y_val)
y_pve = [ely[1] for ely in y1]
return x, x_range, y_nve, y_pve
def parabolic_ins():
x, x_range, y_nve, y_pve = rec()
nl = []
xr = []
for xp, yp in zip(x, y_pve):
if -7 <= xp <= 7:
a = 1
b = 0
c = 2
yc = yp
yp = a * (xp ** 2) # yp value should not cross 35 so that parabola doesn't shift with corner edge
if yp <= yc:
nl.append(yp)
xr.append(xp)
print(nl, xr)
else:
nl.append(yp)
xr.append(xp)
nk = [-x for x in nl]
aa = xr + xr
bb = nl + nk
plt.plot(aa, bb)
# plt.axis([x_range, nl])
plt.show()
parabolic_ins()
I am writing a code to plot roller contours. The radius of the roller may differ and the contour that I am trying to get is a concave parabola. The requirement is that I should be able to generate random roller contours with different radiuses and different parabola-like structures in between them. Below is the sample code I wrote but want it to be more generic and also want to use the random function in python for generating random contours.
Could someone please help? I need to generate n number of rollers with different radiuses and different parabolic shapes in between the line segment. Also, the parabola should not always have to be lying on the y = 0. It should be able to move left and right.
import matplotlib.pyplot as plt
import numpy as np
import random
def rec():
x = list(np.arange(-15, 16, 1))
y = [-35, 35]
y0 = []
for xv in x:
p = (xv, y[0])
y0.append(p)
y1 = []
for xv in x:
q = (xv, y[-1])
y1.append(q)
# plt.plot(x_val, y_val)
x_range = [elx[0] for elx in y0]
y_nve = [ely[1] for ely in y0]
# plt.plot(x_val, y_val)
y_pve = [ely[1] for ely in y1]
return x, x_range, y_nve, y_pve
def parabolic_ins():
x, x_range, y_nve, y_pve = rec()
nl = []
xr = []
for xp, yp in zip(x, y_pve):
if -7 <= xp <= 7:
a = 1
b = 0
c = 2
yc = yp
yp = a * (xp ** 2) # yp value should not cross 35 so that parabola doesn't shift with corner edge
if yp <= yc:
nl.append(yp)
xr.append(xp)
print(nl, xr)
else:
nl.append(yp)
xr.append(xp)
nk = [-x for x in nl]
aa = xr + xr
bb = nl + nk
plt.plot(aa, bb)
# plt.axis([x_range, nl])
plt.show()
parabolic_ins()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论