Factor cos(angle distance) into separate function