measure - 3 points distance calculation strategy -


problem: have (lat-long) co-ordinates of lot of points a, b, c, d . . . in database. now, when choose point a, need calculate distances of point each of other points , closest 1 eg. math requires cos , tan calculations of points. seems quite expensive on db side.

so thought of strategy simplify this. below explanation of strategy.

i have 3 known points (x, y, z) distance between 1 point other known. example lets assume 10. i.e. distance x y = 10; y z = 10; z x = 10. (this forms equilateral triangle. real scenario might not case)

now lets have 2 points , b. calculate distances of point x, y , z , store respectively , point b. (say application logic)

so have:

  • for point a: ax, ay , az
  • for point b: bx, , bz

as strategy, question how can calculate distance between point point b.

as problem itself, if apply above strategy it, question simplifying or complicating situation?

thanks in advance answer.

you can calculate distance between 2 points using pythagorean theorem assuming given in cartesian coordinates, no expensive trigonometry involved.

but still expensive if have thousands or millions of points. depending on database use may offer spatial data types , can handle query efficiently. see example spatial data in sql server.

if database not support spatial data problem becomes quite complex. need spatial index efficient support nearest neighbor queries. can start @ wikipedia article on spatial databases learn how problem solved.

if set of points stable option precompute , store nearest neighbor every point tricky when points added, deleted or changed.


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -