Hi,
So I working on a search algorithm, however, we were asked to compute the distance between the nodes(points(x,y)), and once the distance is computed, then store it into a matrix, which then we perform a look up and let the search algorithm know which distance is closer to the goal node, and hence it will follow that route, and adding the distances.
Here's my question:
I been looking all over to find an specific examples, but did not find any.
The problem is that my points are read from a input file(.txt), so while I am able to get it to read the input files and get the x's and y's, I am still lost on how can I compute their distances of each two points and then storing it to a matrix.
This what I have so far:
Code:
...
int main() {
int x, y;
float distance;
Graph g(4); //Create 4 vertices.
ifstream read("test.txt");
while(read>>x>>y) {
//distance = sqrt(pow(x, 2) + pow(y, 2));
}
//cout << distance << "" << endl;
return 0;
}
Note that I the distance is probably wrong since there are different points, but am not sure how to get around it .
Any example links, or explanations would be HELPFUL!!
It been driving me nuts.