Jump to content

Python In Houdini Error Distance Finder


ZeLemur

Recommended Posts

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])

Link to comment
Share on other sites

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?)

  • Like 1
Link to comment
Share on other sites

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. :unsure:

Link to comment
Share on other sites

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

:)

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...