我已经编写了下面的代码,它应该采用两组xyz点并将它们彼此靠得更近,例如,列表1中的点x1应该移动到列表2中的点x1等。这应该发生在很多步骤上,所以如果我希望它超过5个步骤,我将获得5个列表,list1,list2和3个中间列表。
def generate_steps(p1, p2, steps): # p1 = list1, p2 = list2
percent = 1.0 / float(steps - 1)
points = [] # list of the lists
for i in range(steps):
nudged = nudge(p1, p2, (i * percent)) # generates a point in between l1 and l2
print 'appending %s to the list points' % p1[0]
points.append(p1) # appends list p1 to the list points
return points
def nudge(t1, t2, percent): # t1 = list1, t2 = list2
temp = t1 # copies t1 as a temporary variable, temp
for i in range(len(t1)):
delta_z = (t1[i][-1]) - (t2[i][-1]) # finds the difference between the points in each list
delta_y = (t1[i][-2]) - (t2[i][-2])
delta_x = (t1[i][-3]) - (t2[i][-3])
step_x = percent * delta_x # calculates how far the step must be taken
step_y = percent * delta_y
step_z = percent * delta_z
temp[i][-1] = t1[i][-1] - step_z # modifies temp to be closer to the list l2
temp[i][-2] = t1[i][-2] - step_y
temp[i][-3] = t1[i][-3] - step_x
return temp
pointss = generate_steps(l1, l2, 5)
for i in range(len(pointss)):
print i
print pointss[i]
当我在循环中打印p1时,我会得到一系列不同的值,即使我无法找到应该使p1更改的代码中的任何位置:
appending [1.0, 'T', 230.0, 'ZN', 0.00215020500632, 0.001299689016483, 0.06892444046125] to the list points
appending [1.0, 'T', 230.0, 'ZN', 0.0018009683265599401, 0.00111555626549302, 0.06920025442698] to the list points
appending [1.0, 'T', 230.0, 'ZN', 0.001242189638943844, 0.0008209438639090519, 0.069641556772148] to the list points
appending [1.0, 'T', 230.0, 'ZN', 0.0007392888200893575, 0.0005557927024834807, 0.0700387288827992] to the list points
appending [1.0, 'T', 230.0, 'ZN', 0.0004710750500336315, 0.0004143787497231761, 0.07025055400847985] to the list points
更奇怪的是,当我打印列表点时,每次在循环期间附加了p1的值,每个点都是相同的,虽然它不是起点,但是终点:
[1.0, 'T', 230.0, 'ZN', 0.0004040216075197, 0.0003790252615331, 0.0703035102899]
[1.0, 'T', 230.0, 'ZN', 0.0004040216075197, 0.0003790252615331, 0.0703035102899]
[1.0, 'T', 230.0, 'ZN', 0.0004040216075197, 0.0003790252615331, 0.0703035102899]
[1.0, 'T', 230.0, 'ZN', 0.0004040216075197, 0.0003790252615331, 0.0703035102899]
[1.0, 'T', 230.0, 'ZN', 0.0004040216075197, 0.0003790252615331, 0.0703035102899]
我知道我应该追加点“轻推”#39;列表点,但这导致相同的事情,现在我更好奇为什么p2的值正在改变,以及为什么它没有正确地附加到列表。