Coordinate System - OpenLearning

Nicholas Hurden

nicholas.hurden

The alternative coordinate system used in mechanicalTurk.c allowed for easier calculations of adjacency for regions, arcs and vertices.

It was assumed that the region -2,0 in the lower left of the map would correspond to location 1,1 in this coordinate system, and that all land regions would be positive integers.

 

 

 

These coordinates made calculation of adjacent regions, arcs and vertices trivial for every region, arc and vertex. For example, to get all three vertices adjacent to any other vertex:

static location * vertexAdjacentVertices(location vertex, gameState *gs) {
    location vertices[3];
    
    if (vertex.y % 2) {
        //Odd y coordinates are on the right side of horizontal arcs
        location leftVertex = getVertexLocation(gs, vertex.x-1, vertex.y-1);
        location upperRightVertex = getVertexLocation(gs, vertex.x+1, vertex.y+1);
        location lowerRightVertex = getVertexLocation(gs, vertex.x+1, vertex.y-1);
        
        vertices[0] = leftVertex;
        vertices[1] = upperRightVertex;
        vertices[2] = lowerRightVertex;
    } else {
        //Even y coordinates are on the left side of horizontal arcs
        location rightVertex = getVertexLocation(gs, vertex.x+1, vertex.y+1);
        location upperLeftVertex = getVertexLocation(gs, vertex.x-1, vertex.y+1);
        location lowerLeftVertex = getVertexLocation(gs, vertex.x-1, vertex.y-1);
        
        vertices[0] = rightVertex;
        vertices[1] = upperLeftVertex;
        vertices[2] = lowerLeftVertex;
    }
    
    location *retval = malloc(3 * sizeof(location));
    memcpy(retval, vertices, 3 * sizeof(location));
    
    return retval;
}

 

 

 

Comments

Chat