Accelerometers
Let’s start by simplifying the problem. Your phone (and your Wii controller, I believe) have three accelerometers oriented at right angles to one another. We’re going to study the behavior of just one accelerometer. Once you understand the behavior of one, extending it to three is easy.