how to draw lines betwee a group of points based on distance

   13089   13   3
User Avatar
Member
479 posts
Joined: Dec. 2009
Offline
suppose I have a group of 50 points, how to draw lines between each pair of points based on a distance threshold?

something like the following:
http://albertomoss.com/img/med/googlewallpapers_med_0002.jpg [albertomoss.com]

I couldn't think of an easy way to do it using the default geometry nodes…

I assume there might be a generic algorithm to do this, something like:
1. draw lines from a point to all other points within certain distance
2. remove the above point from the point list (this is to avoid duplicated lines between a pair of point)
3. repeat step 1 for a point in the updated point list

But, I don't know how to do it using python in Houdini…

Thanks!

Attachments:
clustering_v002.hipnc (72.2 KB)
Capture.PNG (197.2 KB)

User Avatar
Member
443 posts
Joined: Sept. 2012
Offline
There you go……….

Attachments:
clustering_points.hipnc (81.7 KB)

User Avatar
Member
443 posts
Joined: Sept. 2012
Offline
I couldn't think of an easy way to do it using the default geometry nodes…

No, not quite right.

This can be easily done in CVEX context (attribvop) using default nodes like addprim, addvertex and forloop vop.
I used VEX(AttribWrangle) which is just the same if you love to code.
User Avatar
Member
443 posts
Joined: Sept. 2012
Offline
If you want I can build this in VOPs for you.
User Avatar
Member
479 posts
Joined: Dec. 2009
Offline
Thank you very much, Pradeepbarua!

Grateful if you can share the VOPs solution!

I'm trying to use the following Python node to do it, but I still can't get it working and no line is drawn …. Appreciate if you can take a look and point out the source of problem of my approach!

# geo_ref node is the one with all the points
# geo node is the one to which all lines will be added
# I use a 2D array to register if one pair of points is already connected

node = hou.pwd()
geo = node.geometry()

geo_ref = hou.node(“../scatter1”).geometry()

# Add code to modify contents of geo.
# Use drop down menu to select examples.

points = geo_ref.points()
num_pt = len(points)

Matrix = [ for x in range(num_pt)]

cnt = 0;
for pt in points:
print “point”, cnt, pt.position()

pt_pos = pt.position()

cntt = 0
for ptt in points:
ptt_pos = ptt.position()

# get the distance between pt and ppt
dist = pt_pos.distanceTo(ptt_pos)
print “dist btw pt”, cnt, “and pt”, cntt, “is:”, dist

connected_or_not = Matrix

# if the distance < threshold of 0.5
# and if the connection betwee the pair is not marked as “connected”
# then draw a line between pt and ppt
# and mark this pair as “connected”

if dist <= 0.5 and dist != 0 and connected_or_not == 0 :
print “draw a line btw pt”, cnt, “and pt”, cntt

line = geo.createPolygon()

l_s = geo.createPoint()
l_s.setPosition(pt.position())
line.addVertex(l_s)

l_e = geo.createPoint()
l_e.setPosition(ptt.position())
line.addVertex(l_e)

Matrix = 1

cntt +=1

cnt +=1

Attachments:
clustering_v009.hipnc (163.5 KB)

User Avatar
Member
479 posts
Joined: Dec. 2009
Offline
… minor update of the approach that is not working ….


node = hou.pwd()
geo = node.geometry()

geo_ref = hou.node(“../scatter1”).geometry()

# Add code to modify contents of geo.
# Use drop down menu to select examples.

points = geo_ref.points()
num_pt = len(points)

Matrix = [ for x in range(num_pt)]

cnt = 0;
for pt in points:
print “point”, cnt, pt.position()

pt_pos = pt.position()

cntt = 0
for ptt in points:
ptt_pos = ptt.position()

# get the distance between pt and ppt
dist = pt_pos.distanceTo(ptt_pos)
print “dist btw pt”, cnt, “and pt”, cntt, “is:”, dist

connected_or_not1 = Matrix
connected_or_not2 = Matrix

# if the distance < threshold of 0.5
# and if the connection betwee the pair is not marked as “connected”
# then draw a line between pt and ppt
# and mark this pair as “connected”

if dist <= 0.5 and dist != 0 and connected_or_not1 == 0 and connected_or_not2 == 0:
print “draw a line btw pt”, cnt, “and pt”, cntt

line = geo.createPolygon()

l_s = geo.createPoint()
l_s.setPosition(pt.position())
line.addVertex(l_s)

l_e = geo.createPoint()
l_e.setPosition(ptt.position())
line.addVertex(l_e)

Matrix = 1
Matrix = 1

cntt +=1

cnt +=1

Attachments:
clustering_v010.hipnc (163.6 KB)

User Avatar
Member
443 posts
Joined: Sept. 2012
Offline
Here is VOPs solution.

Attachments:
clustering_points_VOPs.hipnc (106.8 KB)

User Avatar
Member
606 posts
Joined: May 2007
Offline
There is also the Connect Adjacent Pieces SOP, in Points mode..
User Avatar
Member
443 posts
Joined: Sept. 2012
Offline
Connect Adjacent Pieces SOP design to connect pieces created by voronoi fracture sop.
But yeah you can use it with any other geometry if it have name attribute.
User Avatar
Member
479 posts
Joined: Dec. 2009
Offline
Thanks, PradeepBarua!

Can you and friends here also kindly advise why my python approach shown above doesn't work?

Thanks a lot!
User Avatar
Member
479 posts
Joined: Dec. 2009
Offline
sorry, I found my python approach did work, but a fuse node is needed to merge the overlapping points generated in the process.

Moreover, I found that PradeepBarua's approach may not work when try to get the max number of lines between all the points, e.g. there are 45 lines btw 10 points maximally… Can PradeepBarua kindly check and advise?

BTW, the popnet node is to animate the points which gives interesting results, and pls try out by using the delete7 node as input!

One problem is that I don't know how to “kill” those points reaching their life span which stop at the outermost region ….
Edited by - Feb. 27, 2015 09:49:16

Attachments:
Screen Shot 2015-02-27 at 10.37.13 pm.png (211.0 KB)
clustering_v013.hipnc (218.6 KB)
Screen Shot 2015-02-27 at 10.43.41 pm.png (47.7 KB)

User Avatar
Member
387 posts
Joined: Nov. 2008
Offline
Change:


line = geo.createPolygon()
to:

line = geo.createPolygon()
line.setIsClosed(0)

You need to define polygon as open, otherwise it's closed by default.

Better solution would be create new Python type Operator and use existing points (from the first input). In your approach you are creating too many new ones that you don't need.

Attachments:
connect_pnts_pz_SOP_v1.0.otl (3.9 KB)

User Avatar
Member
479 posts
Joined: Dec. 2009
Offline
thank you very much, pezetko!

Learned a lot from your advices!
User Avatar
Member
479 posts
Joined: Dec. 2009
Offline
… update

Attachments:
clustering_v018.hipnc (235.4 KB)
Screen Shot 2015-02-27 at 11.22.36 pm.png (271.7 KB)

  • Quick Links