Is it possible to create an algorithm which will return an ordered list of vectors representing the main eight directions on a 2d map? I do not want to hardcode the values, nor use a huge if/then/else or case tree if possible.
Here are the vectors I need to calculate, in order:
0, -1
1, -1
1, 0
1, 1
0, 1
-1, 1
-1, 0
-1, -1
Based on the following diagram, I need to generate the vector at the top first, then iterate clockwise for the rest:
(I have a two dimensional array - x and y values - for a total of eight character positions. Each character starts in the center. I want to be able to generate each vector, in order, as I loop through the characters and then add the vector's x and y components to the associated character's position so that each character moves outward from the center in their associated direction.)
Do you see a pattern in those numbers above? Is it possible to devise an algorithm which will generate these pairs in the correct order or am I stuck with hard-coding them?