Math question

Crazy Horse

Newbie
Joined
Jul 14, 2006
Messages
184
Reaction score
0
What we have here is a graph that wraps around (like the map in the game Pacman).The point (90,80) is 20 units away from both (90,100) and (90,0), as well as from (90,60)... etc.

graph.jpg




I am writing an algorithm that requires a single mathematical equation (for each dimension) to find the shortest distance between any two points (Ax,Ay), (Bx,By) on the graph. The distance can be split up into the 2 dimensions. You can use absolute value, modulus, *, /, -, +.

I gave up after about 15-20 minutes, but my brother managed to solve it for me. It's a neat problem, and I would like to see if anyone else is bored enough to give it a shot. I'm not exactly sure how hard it is (my brother said it was "easy" but it took him a bit longer than usual to solve it).


edit:

The domain is (0,0) to (100,100)
 
lol, I don't even understand the question...
 
If you just need the shortest distance between x values, and between y values, could you just use the fact that the largest value is 50, then base your equation off of that.

So looking for patterns, say you have one point at x=90 and are moving the other point along the x-axis. If the other point is at 0, your "normal" distance would be 90, shortest dist is 10. Continuing... (first number is coord of pt 1, second value is coord of pt 2, third number is the "normal" distance, second number is the shortest distance taking into account the wrap-around)
90-10 --> 80/20
90-20 --> 70/30
90-30 --> 60/40
90-40 --> 50/50

Looking at this pattern for a while they arrange themselves around 50 as a kind of central value, so you'd need to be using a difference from 50. You also need to take into account that for say 90-50 the normal distance is also the shortest distance.

And by magic the formula 50-abs(xa-xb-50) works.

If you allow values like 110 and stuff then you would have to use that value modulus 100 to get back onto your normal coordinate plane, then plug the mod values in for xa and xb above.

Do the same for y values.

If you only need the shortest horizontal and vertical distances that should do it. If you want actual shortest distance (allowing diagonals)... use the Pythagorean theorem?

Does that work? I can't bother to test it out much. It's 4 AM here. :O

Edit: Actually make that 50 - abs[abs(xa-xb)-50]. I think...
 
His drawing of his problem is impossible in this world. Its like a donut thats in another dimension.
 
True. I guess you could take a square, tape opposite sides together, and curl the cylinder into a donut but the distances along the inside of the ring versus the outside of the ring would be distorted.

But if you were just making a game like Asteroids or something, I guess it doesn't really matter :P.
 
dfc05:

You got it. :D

I forgot to restrict the domain to 0,0 to 100,100 in the original question, my mistake.
 
All I know is that I need to dodge the ghosts.
 
Back
Top