I'm currently trying to create a video game where characters are AI and are in a circular map with ressources on it.
I'm currently trying to calculate the shortest distance betwing 2 points on this map but my problem is that the map is circular : for example
if my map is 20*20 and i m in (0,0) the (19,0) point has a distance on 1 only. I've been looking on the internet but i didn't found answers for my problem. I have to take care of the orientation (North South west East) of my character too, in he has to turn to go to the point, the distance has to be longer.
Is there an existing formula ?
Thanks for reading !
Their distance then is d=√(x1−x2)2+(y1−y2)2+(z1−z2)2 .
Distance between two points is the length of the line segment that connects the two points in a plane. The formula to find the distance between the two points is usually given by d=√((x2 – x1)² + (y2 – y1)²). This formula is used to find the distance between any two points on a coordinate plane or x-y plane.
For every coordinate choose the minimal distance, and then use it as usual.
int dx = min(abs(x0-x1),20-abs(x0-x1));
int dy = min(abs(y0-y1),20-abs(y0-y1));
For euclid distance :
double dist = sqrt(dx * dx + dy * dy);
For Manhattan distance:
int dist = dx + dy;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With