Calculate distances only vectors that are within a specific area

Hi guys

I have to check the distances of each of the vectors (saved in a array) to the position of character, I would like to know if its possible to include in the calculation only the vectors that are within a area specified, in the same way that work triggers and save resources hardware.

The situation is that by checking each distance of all vectors in the array makes the frames fall, so I need only to include in the calculation of the vectors that are within the indicated area. I would to see if you guys can help me with this, I would be very grateful.

Yup. The secret is a smart data structure like a quad tree or oct tree.

2 Likes

Thank you very much for the reply, I did a quick search on the internet and looks more complicated than I thought, work on it immediately.

Have a look at dichotomic search. Quadtree and octree (or k-d tree) are based on it.

1 Like