# 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 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);
}```

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

connect_point_clouds.hiplc

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

##### Share on other sites

OK, understood.

Thank you Thomas.

##### Share on other sites

• 10 months later...

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?

Edited by Tanghe

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

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×