The relationship between a shepherd and his sheepdog has always seemed almost magical, but scientists now say it can be explained by two simple rules.

Researchers have used GPS data to reveal the mathematical secrets of how sheepdogs do their job.

The new model helps to explain why one shepherd and a single dog can herd an unruly flock of more than 100 sheep.

It could be used to help develop "shepherd robots", for controlling crowds or cleaning up an oil spill.

Dr Andrew King of Swansea University helped to design backpacks fitted with highly accurate GPS technology. These trackers were attached to a flock of sheep and a sheepdog.

Dr King, a behavioural ecologist, explained to BBC Radio Wales' Kayley Thomas what he did.