coordinate systems - How can I calculate the distance between two points in Cartesian space while respecting Asteroids style wrap around? -


i have 2 points (x1, y1) , (x2,y2) 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) + (dy * dy)); 

there's correspondence here between rollover behavior of x , y coordinates , rollover behavior of signed integers represented using base's complement representation in method of complements.

if coordinate bounds map bounds of binary integer type supported language, can take advantage of two's complement representation used current machines performing subtraction directly, ignoring overflow , reinterpreting result signed value of same size original coordinate. in general case, you're not going lucky, above dance abs, compare , subtract required.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -