Design a program to make a polyline pass through these points on the rectangle in random order without repeating and connecting with points on the same straight line, and finally return to the original point.
Hello
strange wording!!!
If it is a question, there are many solutions, TSP is one of the solution
…
You’re looking for what is called a Hamiltonian cycle or circuit (cf. wiki) in an undirected graph (of points), which visits every node exactly once (cf. example code).
Respectfully, the TSP is overkill for this.
On top you’d have to check whether a connection from the previous and the current point to the next candidate is colinear, to prevent “connecting with points on the same line”.
This can be done by calculating the determinant (cf. wiki) of three points, which when 0.0, means that they all lie on the same line. The determinant is usually used to compute the winding of polygons, which plays a role in many computational geometry problems, for instance in some polygon point containment tests.
All of the above requires either Python or C# scripting, since I don’t think that there’s any plug-in that can handle all of it.
A less elegant vanilla Grasshopper method to accomplish something similar, could be to simply random shuffle your points a lot of times or preferably use some plug-in (?) to get all possible permutations of the same set.
Then weed out all identical point sets with the same point order to get rid of duplicates, and finally cull self-intersecting polycurves, if you don’t want those.