Fioxman Posted January 13, 2019 Share Posted January 13, 2019 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. Quote Link to comment Share on other sites More sharing options...
konstantin magnus Posted January 13, 2019 Share Posted January 13, 2019 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); } With sorting out points however you will probably need a sequentiell approach using arrays. connect_point_clouds.hiplc Quote Link to comment Share on other sites More sharing options...
anim Posted January 13, 2019 Share Posted January 13, 2019 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 Quote Link to comment Share on other sites More sharing options...
Fioxman Posted January 13, 2019 Author Share Posted January 13, 2019 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. Quote Link to comment Share on other sites More sharing options...
Fioxman Posted January 14, 2019 Author Share Posted January 14, 2019 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... Quote Link to comment Share on other sites More sharing options...
anim Posted January 14, 2019 Share Posted January 14, 2019 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 1 Quote Link to comment Share on other sites More sharing options...
Fioxman Posted January 14, 2019 Author Share Posted January 14, 2019 OK, understood. Thank you Thomas. Quote Link to comment Share on other sites More sharing options...
Tanghe Posted December 4, 2019 Share Posted December 4, 2019 (edited) 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 December 4, 2019 by Tanghe Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.