Skip to main content
Clarified by removing fluff and adding tags.
Source Link
Anko
  • 13.5k
  • 10
  • 56
  • 82

Given a list of In 2D locations and sizes, how cando I efficiently find the nearest object to some targeta point?

I have a sizable game engine and I'd like a feature for finding the nearest of a list of points.

I could simply use the Pythagorean theorem to find the distances. I know I can't simply add x and y, because that's only theeach distance toand choose the object if you took only right-angled turns. I'm wondering if there's something else I could dominimum one, but that requires iterating through all of them.

I also have a collision system, where essentially I turn objects into smaller objects on a smaller grid, kind (kind of like a minimap,) and only if objects exist in the same gridspace do I check for collisions. I could do that, only make the grid spacing larger to check for closeness. (Rather than checking every single object.) However, that would take additional setup in my base class and clutter up the already cluttered object. Is it worth it?

tl;dr: Is there something efficient and accurate I could use to detect which object is closest, based on a list of points and sizes?

Given a list of 2D locations and sizes, how can I efficiently find the nearest object to some target?

I have a sizable game engine and I'd like a feature for finding the nearest of a list of points.

I could simply use the Pythagorean theorem to find the distances. I know I can't simply add x and y, because that's only the distance to the object if you took only right-angled turns. I'm wondering if there's something else I could do.

I also have a collision system, where essentially I turn objects into smaller objects on a smaller grid, kind of like a minimap, and only if objects exist in the same gridspace do I check for collisions. I could do that, only make the grid spacing larger to check for closeness. (Rather than checking every single object.) However, that would take additional setup in my base class and clutter up the already cluttered object.

tl;dr: Is there something efficient and accurate I could detect which object is closest, based on a list of points and sizes?

In 2D, how do I efficiently find the nearest object to a point?

I have a sizable game engine and I'd like a feature for finding the nearest of a list of points.

I could simply use the Pythagorean theorem to find each distance and choose the minimum one, but that requires iterating through all of them.

I also have a collision system, where essentially I turn objects into smaller objects on a smaller grid (kind of like a minimap) and only if objects exist in the same gridspace do I check for collisions. I could do that, only make the grid spacing larger to check for closeness. (Rather than checking every single object.) However, that would take additional setup in my base class and clutter up the already cluttered object. Is it worth it?

Is there something efficient and accurate I could use to detect which object is closest, based on a list of points and sizes?

edited title
Link
user1430
user1430

Finding Given a list of 2D locations and sizes, how can I efficiently find the nearest object to some target?

Condensed where I could. Some clarifications to grammar & word order.
Source Link
Anko
  • 13.5k
  • 10
  • 56
  • 82

Find Nearest Object Finding the nearest object

I have a fairly sizable game engine created, and I'm adding some needed features, such as this, how do I findI'd like a feature for finding the nearest object fromof a list of points?.

In this case, I could simply use the Pythagorean theoremPythagorean theorem to find the distance, and check the resultsdistances. I know I can't simply add x and y, because that's only the distance to the object, if you only took only right angle-angled turns. However I'm wondering if there's something else else I could do?.

I also have a collision system, where essentially I turn objects into smaller objects on a smaller grid, kind of like a minimap, and only if objects exist in the same gridspace do I check for collisions,. I could do the same thingthat, only make the gridspacegrid spacing larger to check for closeness. (ratherRather than checking every. single. object.) howeverHowever, that would take additional setup in my base class and clutter up the already cluttered object.

TL;DR Questiontl;dr:

  Is there something efficient and accurate that I can use tocould detect which object is closest, based on a list of points and sizes?

Find Nearest Object

I have a fairly sizable game engine created, and I'm adding some needed features, such as this, how do I find the nearest object from a list of points?

In this case, I could simply use the Pythagorean theorem to find the distance, and check the results. I know I can't simply add x and y, because that's the distance to the object, if you only took right angle turns. However I'm wondering if there's something else I could do?

I also have a collision system, where essentially I turn objects into smaller objects on a smaller grid, kind of like a minimap, and only if objects exist in the same gridspace do I check for collisions, I could do the same thing, only make the gridspace larger to check for closeness. (rather than checking every. single. object) however that would take additional setup in my base class and clutter up the already cluttered object.

TL;DR Question:

  Is there something efficient and accurate that I can use to detect which object is closest, based on a list of points and sizes?

Finding the nearest object

I have a sizable game engine and I'd like a feature for finding the nearest of a list of points.

I could simply use the Pythagorean theorem to find the distances. I know I can't simply add x and y, because that's only the distance to the object if you took only right-angled turns. I'm wondering if there's something else I could do.

I also have a collision system, where essentially I turn objects into smaller objects on a smaller grid, kind of like a minimap, and only if objects exist in the same gridspace do I check for collisions. I could do that, only make the grid spacing larger to check for closeness. (Rather than checking every single object.) However, that would take additional setup in my base class and clutter up the already cluttered object.

tl;dr: Is there something efficient and accurate I could detect which object is closest, based on a list of points and sizes?

Tweeted twitter.com/#!/StackGameDev/status/86817874261446656
Source Link
ultifinitus
  • 1.9k
  • 1
  • 16
  • 19
Loading