I've written the following code that should take two sets of xyz points and move them closer to each other, for example, the point x1 in list 1 should move to the point x1 in list 2 etc. This should happen over a number of steps, so if I want it to happen over 5 steps, I'll be given five lists, list1, list2, and three intermediate lists.
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]
When I print p1 in the loop, I'll get a series of different values, even though I can't find anywhere in the code that should make p1 change:
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
Even stranger, when I print the list points, which the values of p1 were appended each time during the loop, every point is the same, although it is not the starting point, but the end point:
[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]
I know I should be appending the point 'nudged' to the list points, but this results in the same thing, and right now I'm more curious as to why the value of p2 is changing, and why it is not appending to the list properly.