how to draw lines betwee a group of points based on distance
13089 13 3- oat
- 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!
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!
- PradeepBarua
- Member
- 443 posts
- Joined: Sept. 2012
- Offline
- PradeepBarua
- Member
- 443 posts
- Joined: Sept. 2012
- Offline
- PradeepBarua
- Member
- 443 posts
- Joined: Sept. 2012
- Offline
- oat
- 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
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
- oat
- 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
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
- PradeepBarua
- Member
- 443 posts
- Joined: Sept. 2012
- Offline
- eetu
- Member
- 606 posts
- Joined: May 2007
- Offline
- PradeepBarua
- Member
- 443 posts
- Joined: Sept. 2012
- Offline
- oat
- Member
- 479 posts
- Joined: Dec. 2009
- Offline
- oat
- 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 ….
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
- pezetko
- 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.
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.
- oat
- Member
- 479 posts
- Joined: Dec. 2009
- Offline
- oat
- Member
- 479 posts
- Joined: Dec. 2009
- Offline
-
- Quick Links