I have a code with all this so far:
import math
nList = [[[0,0,0],[3,2,1]],\
[[]],\
[[1,1,12]],\
[[0,0,0],[30000,40,3010],[32000,40500,7520],[0,0,10520]],\
[[15340,0,0],[104300,0,3630], [434000,4434000,63460],[400340, 404300, 9430],[10340,0,1334320]]]
MaxLengthPerTrace=[[]]
traceCount = len(nList)
prevX = 0
prevY = 0
prevT = 0
maxLengthTempList=0
def calculateLength(x1, y1, x2, y2):
return math.sqrt((x1-x2)**2 + (y1 - y2)**2)
def calculateTime (t1,t2):
return abs(t1-t2)
#Entry point
for traceIndex in range(0, len(nList)):
print 'trace: ' + str(traceIndex+1)
trace = nList[traceIndex]
for pointIndex in range(0, len(trace)):
point = trace[pointIndex]
if len(point)>0:
tempX = point[0]
tempY = point[1]
tempT = point[2]
if pointIndex != 0:
#Calulate Length here
length = calculateLength(tempX, tempY, prevX, prevY)
print length
#Calculate Maximum Length here
How would I write a program to calculate a maximum length from length? I wrote pseudo-code for this as
if(length > max)
max = length;
add the length in MaxLengthPerTrace in index of traceindex
but can't seem to execute it in Python 2.7.10 properly. Any help would be appreciated. Thanks!
I tried this but it didn't work, coming with error: "for i in length: TypeError: 'float' object is not iterable"
for i in length:
if i >length:
i=length
MaxLengthPerTrace.append(i)
print MaxLengthPerTrace