Slight optimization possible here: instead of finding the real distance with sqrt and comparing against 30, you can find the squared distance and compare against 900 (that is, 30^2).