Mathematicians uncover the logic behind how people walk in crowds