ZeLemur Posted January 13, 2012 Share Posted January 13, 2012 I am sure i am just over thinking this however i believe i am just messing up searching and sorting a list with in a list Any Help would be appreciated. import math import random geo=hou.pwd().geometry() #x will equal total number of points x=10 LOOT = range(0,x) while len(LOOT) >= 0: #taking the list of the number of particles avalible and choseing one at random CP = LOOT[random.randrange(0,len(LOOT))] apart = [geo.points()[CP].position()] DistanceBP = [0,0] for l in range(0,len(LOOT)): N = LOOT[l] if N == CP: continue elif N != CP: bpart = [geo.points()[N].position()] qrt = math.pow(bpart[0][0]-apart[0][0],2) PW = math.pow(bpart[0][0]-apart[0][0],2)+math.pow(bpart[0][1]-apart[0][1],2)+math.pow(bpart[0][2]-apart[0][2],2) DistanceFinder = math.sqrt(PW) DistanceBP.append([DistanceFinder,N]) #sorting the distance to find the shortest distance and placing them in variables to be transfered to Tesselation DistanceBP.sort() P2a = DistanceBP[1][1]#<-- this is where the error is reporting a problem P3a = DistanceBP[2][1] P2= geo.points()[P2a].position() P3= geo.points()[P3a].position() #removing them from loot LOOT.remove(CP) LOOT.remove(DistanceBP[1][1]) LOOT.remove(DistanceBP[2][1]) Quote Link to comment Share on other sites More sharing options...
magneto Posted January 13, 2012 Share Posted January 13, 2012 I have to run the code to see it better but it seems like you are trying to index into an int, from your DistanceBP list. 1 Quote Link to comment Share on other sites More sharing options...
eetu Posted January 14, 2012 Share Posted January 14, 2012 My first reaction is that DistanceBP is a one-dimensional array of two-element tuples, but you're trying to access it like a two-dimensional array. Then again, the same seems to be happening with apart and bpart, and if they're working then I must be wrong.. (..or do they work because the first subscript is always 0?) 1 Quote Link to comment Share on other sites More sharing options...
ZeLemur Posted January 15, 2012 Author Share Posted January 15, 2012 My first reaction is that DistanceBP is a one-dimensional array of two-element tuples, but you're trying to access it like a two-dimensional array. Then again, the same seems to be happening with apart and bpart, and if they're working then I must be wrong.. (..or do they work because the first subscript is always 0?) I was under the impression that for apart that having brackets would allow me to declare apart as a tuple element. I have yet to test it but i guess that is over kill and python already recognizes it as a tuple from the .position call. Thus it places it in a array because of the brackets. My intention was to create DistanceBP and have that be a list which each element of the list contains two-element tuples. Thus allowing me to run a simple sort() on the distance and then utilize the second element of the tuple containing the points number. So, i guess my question would be where did i go wrong with that. Quote Link to comment Share on other sites More sharing options...
ZeLemur Posted January 18, 2012 Author Share Posted January 18, 2012 i found that the problem was with in my syntax and or with in what the variable that i called on creates. points()[pn].position() returns a vector3. Python has its own vector 3 class which will simplify most of my problems. Thank you all for you help. happy coding Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.