function getPos(num){ var bottomCorner = Math.ceil(Math.sqrt(num)); if(bottomCorner%2 == 0){ bottomCorner++; } var sidelength = bottomCorner - 1; var timesRound = (Math.pow(bottomCorner, 2) - num) / (bottomCorner - 1); var lastsection = timesRound % 1; var centerdistance = (Math.abs(0.5 - lastsection)) * sidelength; console.log((sidelength / 2) + centerdistance); } getPos(325489);