to correct for angle:
call the angle the lower part of the chain makes with the horizontal "alpha". then:
alpha = arctan((r2-r1)/d)
arc around chainring = r2*(pi + alpha)
arc around cog = r1*(pi - alpha)
length on top = d
length on bottom = [(r2-r1)^2 + d^2]^1/2
divide by length of link to get number of links.
round up.