Click here to Skip to main content
15,902,884 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a problem how to create a database that can calculate distance between several points(in (x,y) coordinate) for Ant Colony System..
example: point A(3,5) and point B(4,8)
how to calculate the distance and how to apply this in database..

thank's for help :D
Posted
Comments
pankajupadhyay29 16-Jun-11 0:23am    
you should have some formula to calculate this. I think this is sqrt((x2-x1)^2+(y2-y1)^2) distance between (x1,y1) and (x2,y2).
janalif 16-Jun-11 0:38am    
how about the design of database??
Sergey Alexandrovich Kryukov 16-Jun-11 0:51am    
Not quite clear what is the distance (in metric space of not) and what's the requirements for storage. What do you need to store and why? It should be fairly simple though.

Is it about Ant colony optimization algorithms, http://en.wikipedia.org/wiki/Ant_colony_optimization_algorithms?
--SA
janalif 16-Jun-11 0:57am    
i mean the distance between A and B in metric space.. i need to store x and y coordinate to calculate the distance,,

1 solution

Your question is not clear. What kind of distance you are looking for.If a simple distance between point a and b for example say distance between 3 and 5 is 2 and 4 and 8 is 4 the i'll suggest you to have a table where you can store coordinate x and y and the calculate the distance in your business logic. Do not store any extra/unneeded information in database.

[Update]
Formula to get distance between two coordinate is as follow
sqrt((x1 - x2)^2 + (y1 - y2)^2) if i replace the values of x1,x2,y1,y2 it will look like

sqrt((3-4)^2 + (5-8)^2)

Now you can store all then point in a table with four column.And fetch the points from database and calculate the distance during run-time.

[/Update]
 
Share this answer
 
v3
Comments
janalif 16-Jun-11 0:50am    
i mean, 3 and 5 are value of (x,y) coordinate for A.. so was 4 and 8 are (x,y) coordinate for B,, the question is how to find the distance between A and B??
CS2011 16-Jun-11 1:06am    
I have update my solution.Have a look.
janalif 16-Jun-11 1:18am    
thank's for sharing :) thank's a lot :D
Christian Graus 16-Jun-11 1:30am    
Well done. A database cannot calculate this, this guy is obviously clueless, and you did his homework. When he graduates and still has no clue how to do his work, I hope he works for your company, and not mine.
CS2011 16-Jun-11 1:44am    
Hopefully by that time i'll be away from IT and shooting some nice photograph :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900