Jump to content

How to connect points?


Prabu

Recommended Posts

Hello everybody,

I have a set of points( static particles). their pt numbers are not ordered one But it has unique id and nearest point id stored in an attribute and their distance to nearest point stored in an attribute.

How to connect those pts with their nearest pt. All the suggestions are welcome. Is there any simple solution?

Thanks

-Prabu

Edited by Prabu
Link to comment
Share on other sites

Hello everybody,

I have a set of points( static particles). their pt numbers are not ordered one But it has unique id and nearest point id stored in an attribute and their distance to nearest point stored in an attribute.

Thanks

-Prabu

You can sort points using any existing attribute.

Use sort by expression and supply the variable.

Quick hip is attached.

Cheers,

sort.hipnc

Link to comment
Share on other sites

I think the point was to create a line from each point to it's nearest neighbor.

Maybe ForEach?

Or create as many lines as you have points, and for each line move vertex 0 to the point that has the same number as the line primitive, and vertex 1 to the point that the previous point's nearest-attribute points to.

(contrieved? naah.)

Link to comment
Share on other sites

Sure...

I have attached the file.

Your file is one level of redirection harder - the nearest neighbor does not refer to the point numbers but the particle IDs.

If you click on the "Use Point Numbers Instead of Particle IDs" in your Proximity POP you will have it a bit easier.

Link to comment
Share on other sites

Ive been using pythonSop to generate geometry. for connecting every point to each other(limited with maxDist) would be something like this in pythonSop:

geo = hou.pwd().geometry()

maxDist = 5.0
points = geo.points()

pointNum = 0

for p1 in points:
    for p2 in points:
        if p1.number() != p2.number():
            if p2.number() >= pointNum:
                pos1 = p1.position()
                pos2 = p2.position()
                line = pos1 - pos2
                length = line.length()
                if length < maxDist:
                    poly = geo.createPolygon()
                    poly.setIsClosed(False)
                    posMid = (pos1+pos2)*0.5

                    iter = 0.0
                    for pos in pos1, posMid, pos2:
                        point = geo.createPoint()
                        point.setPosition(pos)
                        poly.addVertex(point)
                        iter += 1
    pointNum = pointNum+1 

Kustaa

Link to comment
Share on other sites

Ive been using pythonSop to generate geometry. for connecting every point to each other(limited with maxDist) would be something like this in pythonSop:

Kustaa

If you would want to speed this up a lot, then you could do the length and closest points calculation in vex/vops (multithreaded) beforehand and in your python code, you would read the attribute values and only create the geometry.

Link to comment
Share on other sites

If you would want to speed this up a lot, then you could do the length and closest points calculation in vex/vops (multithreaded) beforehand and in your python code, you would read the attribute values and only create the geometry.

thats true, on top of being multithreaded im sure that the pc functions are slightly more efficient than my approach =)

Link to comment
Share on other sites

  • 2 weeks later...

Cant you just use a vopsop, import nearest att (make it points instead of id) and then use it to import another att (P) with that id, substract both positions, make it a vector, and then copy stamp lines. Or do I miss something obvious?

Edited by Macha
Link to comment
Share on other sites

Cant you just use a vopsop, import nearest att (make it points instead of id) and then use it to import another att (P) with that id, substract both positions, make it a vector, and then copy stamp lines. Or do I miss something obvious?

I think at some point I did that too, but I found it is more accurate to create a line, set both points of the line to the actual values, rather than have the line be scaled and oriented by the copy sop in the direction between the two points. On a pure theorethical level the resutl should be the same, in practice there are numerical errors that cause inaccuracies (which can cause problems later on if you are planning to fuse the lines, perform connectivity based partitioning, pathfinding algorithms,..). Also the copy sop or the foreach are slow, much rather create all the lines first and then perform the position adjustment in vops.

It is the same kind of per primitive id lookup that is performed on the points in vops as if you were to transform entire '$CLASS' based groups of primitves (with 'class' at the point level).

Link to comment
Share on other sites

  • 2 weeks later...

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