Function which calculates coordinates between given positions