I have a number of clarifying questions I would ask:
1. Are the castle and the compound the same thing?
2. In what direction are i and j relative to your point of view?
3. As a hunch, you're probably going to get a second-order differential equation that you might be able to integrate once exactly. Do you need an exact answer?