Sunday, 15 February 2015

c# - How to find closest point (point being (x,y), in a list of different points) to a given point? -


I currently have a random point randomly generated. I am trying to check whether the given random point It is close to any other point in the plane, if it is far from all the other points, then it will be added to the list of other points. I start with a point and the first charged digits in the list are being generated in this way. My problem is, when I draw all the points in the list on the screen, the numbers are often very close because they should be allowed.

  generic zero generated firstMap () {int calcul = 0; Do {int randXpixels = main.rand.Next (24, main.screenWidth - 16); // Exclude the outer 16 pixels of the empty screen (the planet's spit is 8 pixels in diameter) int randipixels = main. Land. Next (27, Main Sinheit-27); Tupal and lieutenant; Int, int & gt; Corporation = Tupal Crate (randexpx, randipix); If (distance (closest point, coordination) & lt; 200) {continue; } Points. Add (coordinate); // from the list & lt; Tuple & LT; Integer, integer & gt; & Gt; Points; Count ++; } While (calculated & lt; 100); Public Tulle & lt; Int, int & gt; Closest point (Tuple and lieutenium; int, int et p1) {Tuple and leptum; Int, Int & G; P2 = Tupel.Creat (0, 0); Bool firstRun = true; Leading (Tuple and LeTinum; Int, Intuit; Point in Points) {if (firstly) {p2 = point; FirstRun = false; } And if (distance (p1, p2)  

Edit: To be clear, how close that number can be, there is only one number that I have thrown (for now) it can be anything> ~ 30

Edit2: All Tupples were changed to vector 2 and used the suggested code, the problem could not be changed even then

3 Edit: All points (loop) Inside the inside) and using the loop using the loop has fixed the problem for the break.

What about something like this?

  Public Zero Outflow () {int count = 0; Do {bool addPoint = true; Int randXpixels = main.rend. Next (24, Main Side Width - 16); Int randYpixels = Main Land. Next (27, Main Sinheit - 27); For (int a = 0; a & lt; num; number; a ++) {int dX = randXpixels - number [a] .x; Int.dv = randexcel - points [a]. why; If (DX * DX + DY * DY <200) {addPoint = false; break; }} If (Edepoint) digits Add (new point (randxpx, randex); Count ++; } While (calculated & lt; 100); }  

Just change the point class in your tub or whatever you are using


No comments:

Post a Comment