I calculated the velocity that the ball starts moving at and realised that the formula assumes that the cannon is at (0, 0). So I subtracted the cannon's coordinates from the mouse's coordinates.
<img src="http://dl.dropbox.com/u/52788071/cannon_angle2.png" border="0" />
Note: I blurred out parts that are unrelated to the problem.
Now, when the mouse is anywhere to the left of the cannon, it points almost straight up (270.00009316509215 degrees). When the mouse is anywhere to the right of the cannon, it points almost straight down (89.99999794984215 degrees).
Also, the formula assumes that (0, 0) is in the bottom-left corner instead of the top-left. I'm not sure how to correct this.
Can anyone please help?