So, I randomly guessed dd = (length / abs(x0 - x1))^2. It seemed to magically make everything work. Yay!