# Map map coordinates into grid reference id

This topic is 840 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I want to squeeze down the range of ids that identify individual cells of the map.

Like this as follows:

-10,30 (0,0)  0,30 (1,0)   10,30(2,0)
-10,20 (0,1)  0,20 (1,1)   10,20(2,1)
-10,10 (0,2)  0,10 (1,2)   10,10(2,2)
-10,  0 (0,3)  0, 0 (1,3)    10,0 (2,3)


My purpose of this move is to simplify the astar distance between nodes

Say if the true distance is 10.0 units (-10,30) to (0,30), I just want 1

Hope you get what I mean...

How do I go about doing that in C++?

Thanks

Jack

Edited by lucky6969b

##### Share on other sites

In the given example...

newX = (oldX + 10) / 10

newY = (30 - oldY) / 10

##### Share on other sites

I find my map is not perfectly squared at 1:1

newX = (oldX + 10) / 10

newY = (30 - oldY) / 9

okay?

Thanks

Jack

Edited by lucky6969b

##### Share on other sites

Set a reference point ((-10, 30) in your example),  and calculate the delta values, then divide them by 10 :)

int refX = -10;
int refY = -30;

int simpleX = (mapX - refX) / 10;
int simpleY = (mapY - refY) / 10;