# How can I find phase angle based on mouse movement?

It's me again with my ball problematic, after 3 closed questions that really helped me out I figured out I would make a short video, so you'll have a better understanding of the problem. I have this formula:

$$\begin{eqnarray} x(t) &=& A e^{-\gamma t/2} \cos(\omega t - \phi) \\ y(t) &=& B e^{-\gamma t/2} \cos(\omega t - \psi)\\ \end{eqnarray}$$

this formula is for an unforced 2d damped harmonic oscillator and honestly I've tested it and is looks like it's the good one. Now my problem is for $$\phi$$ and $$\psi$$. When I set them to $$0$$ I get an oscillation on a straight line but as you can see in the video I suspect that based on the mouse movement appears a phase shift on either one or two of the axis making the ball rotate around the equilibrium. At this point I'm unable to understand this motion and reproduce it neither knowing which forces are implied.

the description of the motion is the following:

• When I click on the screen the ball gets attracted tho the clicked point
• When I hold the mouse pressed the ball oscillates around the clicked point (equilibrium)
• When I release the mouse, the ball continues it's way based on the direction and velocity of the oscillation
• When reaching the end of the object the ball collides and I guess I only need to change the sign of $$dt$$ (where $$dt$$ is the difference between current frame position and previous one)
• When moving the mouse I guess operates some sort of centripetal force which I'm unable to emulate at this point.

Here is the link to the video

my question is how can I find both phase angles to emulate this motion.

• If the mouse is moved, while it attracts the ball, you need to recalculate your solutions $x(t)$ and $y(t)$ for the new situation, but with the ball's current position and velocity as boundary conditions. I tried to explain the calculation in this answer to one of your previous questions, which you said you did not understand. If you can tell me, which part is difficult for you, I can try to clarify. Otherwise, you should be fine just using the formulas for $A$ and $\phi$ from there.
– sim0
Commented Aug 7, 2021 at 13:23
• @nu ok many thanks for your answer, that's always a relief when somebody answering me , I really need to answer this. So basically you are telling me that your previous answer already solves my answer? Do you mean your equation allows me to reproduce this same motion (I mean at least when I move my mouse and make circles with it for example)? Commented Aug 7, 2021 at 13:29
• Yes, it should allow you to do that. If you knew beforehand how the mouse will move, there are more efficient ways to simulate the ball's motion (that would be numerical integration), but the whole point of user interaction is that the computer does not know what the user will do, so I guess this case is not of interest for you.
– sim0
Commented Aug 7, 2021 at 14:25
• @nu. Great I will ask you questions shortly about your equation, just to clarify few things. At this moment I'm not available, I'll try your equation and what I understand about it tonight and come back to you as soon as possible. Again... many thanks for your help. Commented Aug 7, 2021 at 14:30
• @nu. Hi it's me again. I've looked at your formulas and how can not knowing $\phi$ and $x_0$ I could know $v_0$. by the way what is $v_0$ (the velocity? thanks. Commented Aug 7, 2021 at 20:54

Your damped equations in x and y are basically related to forces: $$\frac{d^2\vec{r}}{d^2t}=\vec{F}/m,$$ where $$\vec{r}=(x,y)$$ in your case. Also the force is 2D. The two dimensions are independent, and it is quite easy to "integrate" your x,y formulas to see the actual forces. By clicking the mouse you create a force and can calculate all the parameters of your formulas (as you did alread, I think).
$$\frac{d^2\vec{r}}{d^2t}=\frac{1}{m} \sum_i \vec{F_i}$$