How do I get the terrain XY coordinates given a world position?

Can you tell me if this is the correct way get the terrain XY coordinates from a raycast hit on the terrain?

Vector2 WorldPosToTerrainXY(Terrain terrain, Vector3 wordCor)
{
    Vector2 vecRet = new Vector2();
            Vector3 terPosition = terrain.transform.position;
            vecRet.x = ((wordCor.x - terPosition.x) / terrain.terrainData.size.x) * terrain.terrainData.heightmapWidth;
            vecRet.y= ((wordCor.z- terPosition.z) / terrain.terrainData.size.z) * terrain.terrainData.heightmapHeight;
            return vecRet;

}
...
Vector2 pos = WorldPosToTerrainXY(terrain, hit.point);
int x = Mathf.RoundToInt(pos.x);
int y = Mathf.RoundToInt(pos.y);

The blue lines in this image are the ray casts (from the center of each hex down on to the terrain), but for some strange reason the heights are being modified at the wrong location on the terrain.
3072047--230986--hexraycast.PNG

It looks like my function above is only rounding the hit locations.
HIT: 31.3, 500.0, 62.5
LOC: 31, 63