Author Topic: How to get the closest entity from a given entity.  (Read 1523 times)

0 Members and 1 Guest are viewing this topic.

teslaxx

  • Guest
How to get the closest entity from a given entity.
« on: December 19, 2011, 01:23:29 PM »
I have a point and 10 DBTexts. How to find (based on the position of the BlockReference) which is the closest DBText? :)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: How to get the closest entity from a given entity.
« Reply #1 on: December 19, 2011, 02:56:23 PM »
I have a point .....

....  How to find (based on the position of the BlockReference)..... 

Is the point a DBPoint or a Point3d ie and entity or a location.

What has the blockreference to do with the 'point'

What do you mean by 'closest'

Nearest to the insertionPoint ?
Nearest to the boundingBox ?

The nearest will be the one with the smallest distance between locations .. so you'll need to compare each.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: How to get the closest entity from a given entity.
« Reply #2 on: December 19, 2011, 03:24:59 PM »
Not necessarily a direct distance comparison for each.  For large numbers of checks, it may be more efficient to sort the list of points (text insertion?) by x/y values, in which case the point (nearest/insert/whatever) would just need to be located between the two list elements (essentially sorting it into the list), maybe with a quick distance check for the surrounding 2-4 points just to avoid local sorting issues.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}