标记点(注释表示“标记点”)的点是将3D绘图中的现有点旋转一个点。基本上我把所有点都移动了60度。出于某种原因,当移动点时,我有两个点重叠。我试过改变我的if语句,并且已经搞乱了他的索引,但还没有成功。我包含整个功能的唯一原因是你可以绘制并看到我遇到的问题。这里是;如果您有任何问题,请与我联系:
def transform_3d_trig(a,b,c):
q=2*math.pi/(360)
d=c*q
a2 = a+b
n = 12
sin=math.sin
cos=math.cos
sqrt=math.sqrt
x = []
y = []
z = []
for i in range(n):
if i <= 5:
x.append(a*np.cos(q*(60*(i-1))))
y.append(a*np.sin(q*(60*(i-1))))
z.append(0)
else:
x.append(a2*np.cos(q*(60*(i-1))))
y.append(a2*np.sin(q*(60*(i-1))))
z.append(0)
x_new = x #new lists
y_new = y
z_new = z
for i in range(n):
y_new[i] = y[i]*cos(d)
z_new[i] = y_new[i]*np.tan(d)
# plot points at this stage (before rotation); no overlapping points
fig = plt.figure(figsize=(12,12))
ax3 = fig.add_subplot(211, projection='3d')
bond2 = [x_new[4],x_new[10],y_new[4],y_new[10],z_new[4],z_new[10]]
ax3.plot(bond2[:2],bond2[2:4],bond2[4:6], color='r')
ax3.scatter(x_new, y_new, z_new)
ax3.set_xlabel('\nX')
ax3.set_ylabel('\nY')
ax3.set_zlabel('\nZ')
x_dummy = x_new #dummy variables to not screw up list
y_dummy = y_new
for i in range(n): #marked spot
if (i == 5 or i == 11):
x_new[i] = x_dummy[i-5]
y_new[i] = y_dummy[i-5]
else:
x_new[i] = x_dummy[i+1]
y_new[i] = y_dummy[i+1]
print(x_new[i], y_new[i]) #to track what point are overlapping
# plot points at this stage (after rotation); overlapping points
ax3 = fig.add_subplot(212, projection='3d')
bond2 = [x_new[4],x_new[10],y_new[4],y_new[10],z_new[4],z_new[10]]
ax3.plot(bond2[:2],bond2[2:4],bond2[4:6], color='r')
ax3.scatter(x_new, y_new, z_new)
ax3.set_xlabel('\nX')
ax3.set_ylabel('\nY')
ax3.set_zlabel('\nZ')
plt.show()
return x, y, z, x_new, y_new, z_new
答案 0 :(得分:1)
问题可能是这些线条没有达到预期的效果:
x_dummy = x_new
y_dummy = y_new
他们不会创建数组的副本,只是复制引用。结果你实际上搞砸了#39;修改_new
&#39;版本时的原始_dummy
数组因为它们是(引用)同一个对象。
要实现您正在寻找的行为(我假设),您需要强制实际复制数据:
x_dummy = x_new.copy()
y_dummy = y_new.copy()