Jump to content

Connecting points in vex


Fioxman

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.

Link to comment
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

Link to comment
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

Link to comment
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...

 

Link to comment
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
Link to comment
Share on other sites

  • 10 months later...

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

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

×
×
  • Create New...