coordinate systems - How can I calculate the distance between two points in Cartesian space while respecting Asteroids style wrap around? -
i have 2 points (x 1 , y 1 ) , (x 2 ,y 2 ) represent location of 2 entities in space. calculate euclidian distance between them using pythagoras' theorem , wonderful. however, if space becomes finite, want define new shortest distance between points "wraps around" seams of map. example, if have point (10, 10) , point b (90,10) , , map 100 units wide, i'd calculate distance between , b 20 (out right edge of map , left edge), instead of 80, normal euclidian distance. i think issue i'm using coordinate system isn't quite right i'm trying do, , flat square map more of seamless doughnut shape. suggestions how implement system of nature , convert , forth cartesian coordinates appreciated too! toroidal plane? okay, i'll bite. var raw_dx = math.abs(x2 - x1); var raw_dy = math.abs(y2 - y1); var dx = (raw_dx < (xmax / 2)) ? raw_dx : xmax - raw_dx; var dy = (raw_dy < (ymax / 2)) ? raw_dy : ymax - raw_dy; var l2dist = math.sqrt((dx * dx)...