Jump to content
Fioxman

Connecting points in vex

Recommended Posts

Hello guys,

i have a little problem in VEX.

I have two point clouds, point cloud 1 with 15 points, and point cloud 2 with more than 500 points.

I want to connect each point of the PC1 with 10 random points of the PC2, with a poly line. And the connected points of the PC2 must not be connected with 2 points of the PC1. (if the point is already connected, skip it).

I'm trying to do that with a point wrangle in a for each loop, but i don't even know how to select 15 random points, it's always the same...

I'm learning vex, but i'm still a beginner, so if someone can help me, at least with the theory, it would be cool ;)

 

François.

Share this post


Link to post
Share on other sites

Leaving out the constraint about no PC2 point used twice, it would be just this between both point clouds:

int connections = 10;
for(int i = 0; i < connections; i++){
    int pt_PC2 = int( rand(@ptnum + 45 * i) * npoints(1) );
    vector pt_pos = point(1, 'P', pt_PC2);
    int pt_add = addpoint(0, pt_pos);
    int prim_add = addprim(0, 'polyline', @ptnum, pt_add);
}

connect_point_clouds.jpg.7fff686a4a1431cc98d2a29efb618bf4.jpg

With sorting out points however you will probably need a sequentiell approach using arrays.

connect_point_clouds.hiplc

Share this post


Link to post
Share on other sites

here is a way without reusing points of PC2 unless there is less points than needed for unique connections

just use Sort SOP to randomize point numbers on PC2 to get different random seed

void line(int in0_pt, in1_pt){
    vector P2 = point(1, "P", in1_pt);
    int pt2 = addpoint(0, P2);
    int prim = addprim(0, "polyline", in0_pt, pt2);
}

int count = chi("count");
int startpt = @ptnum*count; 
for (int i = 0; i<count; i++){
    int in1_pt = startpt + i;
    in1_pt %= npoints(1); 
    line(@ptnum, in1_pt);
}

 

ts_connect_rangom_not_reuse.hip

Share this post


Link to post
Share on other sites

Thank you so much guys!!

It helps a lot.

I had not thought of randomise the point distribution... it's much more simpler.

 

Thanks again.

 

Share this post


Link to post
Share on other sites

Hello Thomas,

I have a question.

I don't understand the line "in1_pt %= npoints(1);"

I have tried to reproduce your setup on my own, and i don't understand the use of this line of code. When i don't use it, it still work.

i'm a bit confused...

 

Share this post


Link to post
Share on other sites
19 minutes ago, Fioxman said:

I don't understand the line "in1_pt %= npoints(1);"

I have tried to reproduce your setup on my own, and i don't understand the use of this line of code. When i don't use it, it still work.

it's a safeguard

it will not allow in1_pt to be larger than number of points of the second input, otherwise it would error out

so if you don't have enough points in the second input to make unique connections it will start to reuse points, hence the use of modulo operator %

so yes, it will work the same if your number of points of PC2 is larger than <n>*PC1 where <n> is the number of connections per point

  • Like 1

Share this post


Link to post
Share on other sites

Using this method seems to remove the name atribute from one of the 2 inputs can someone explain to me how to keep the name attribute?
 

Balljoint.hipnc

Edited by Tanghe

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×