Help with connecting lines by nearest distance

   595   2   1
User Avatar
Member
4 posts
Joined: June 2025
Offline


Houdini Apprentice user here, I've been 4 weeks into it now and I stumbled a pretty solid obstacle for me.

Right now I'm kinda stuck on the logic behind this. How would I make it so that instead of just randomizing the selected points around the circle, how would I make it so it selects the points the closest proximity between two circles? In the reference image I used a very basic random scattering points to form the position of the startpoint and endpoint of each line.

Each line is connected to two circles, but what I want to achieve is that the line would start from the point of the previous circle that is the nearest to the nearest point of the next circle (see reference image), then that next circle would apply the same thing to the very next circle until it reaches the last. (the green ones should be the output)

Probably like a chain of lines that finds the optimal position to form a line between the circles without having to overpass their geometry or overlap maybe.

But yeah, I would gladly accept any solution! 🙏
Edited by iamrheonmaro24 - July 17, 2025 06:18:32

Attachments:
E.png (1.2 MB)

User Avatar
Member
5040 posts
Joined: Feb. 2012
Offline
Hi,

You can use pcfind in VEX to find the nearest point from each circle, sort by distance, and connect the closest points using addprim.



Nearest pt (Point Wrangle):

int pts [ ] = pcfind ( 1, "P", @P, ch("radius"), chi("maxpts") );
i@nearpt = pts [ -1 ];

vector p = point ( 1, "P", i@nearpt );
@dist = distance2 ( @P, p );

Create Line (Detail Wrangle):

vector p0 = point ( 1, "P", 0 );
vector p1 = point ( 2, "P", 0 );

int pt0 = addpoint ( 0, p0 );
int pt1 = addpoint ( 0, p1 );

addprim ( 0, "polyline", pt0, pt1 );

Attachments:
pcfind.png (580.9 KB)

Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com] https://lnk.bio/animatrix [lnk.bio]
User Avatar
Member
443 posts
Joined: April 2018
Offline
Not sure what the intended use case for this is, but you could just pack the circles and connect their centers with the Add SOP. Just merge the packed circles together, then on the Add SOP > Polygons > By Group and they will all immediately connect.

You can then just extrude the circles a bit to hide the bits of the line that pass through them (or even just simply translate the line to be behind the circles - again, I don't know the use case).

Edited by eikonoklastes - July 18, 2025 05:21:13

Attachments:
connected_circles.png (1.3 MB)

  • Quick Links