mardi 12 juillet 2016

Calculating integrer x and y coordinates around point by range variable

The problem didn't let me sleep at night.

Given floating point x and y coordinates of infinite 2D space, and the range variable, I need to get all possible intergrer coordinates that are in range. image

The green blocks are in range, and the red ones are not.

Now, I have an answer, but I'm not sure if it's the best one. Make an 2D array with all the values in a square around the point (from -distance, distance to distance, -distance) and then iterate through the entire array, each time checking the distance if it is closer or further than needed, and if so then insert it into another array.

Aucun commentaire:

Enregistrer un commentaire