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.

  • $\begingroup$ 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. $\endgroup$
    – sim0
    Commented Aug 7, 2021 at 13:23
  • $\begingroup$ @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)? $\endgroup$
    – JSmith
    Commented Aug 7, 2021 at 13:29
  • $\begingroup$ 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. $\endgroup$
    – sim0
    Commented Aug 7, 2021 at 14:25
  • $\begingroup$ @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. $\endgroup$
    – JSmith
    Commented Aug 7, 2021 at 14:30
  • $\begingroup$ @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. $\endgroup$
    – JSmith
    Commented Aug 7, 2021 at 20:54

1 Answer 1


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).

So what happens when you move the mouse while pressing the button?

You have to add up forces. It cannot be a single force, but only the sum of at least two (not parallel) forces that produce the phase shift. Just consider, while you move the mouse, you create a stream of forces, each with a different direction, magnitude -- and each one is damped in time, so the latest one is always dominating:

$$ \frac{d^2\vec{r}}{d^2t}=\frac{1}{m} \sum_i \vec{F_i} $$

If you like, just consider two independent perpendicular forces/movements, add them up, and observe the result.

  • $\begingroup$ thank you for your answer but I've finally found a solution.I don't really understand your answer as I don't see phi or psi in it. would it be possible for you to write the step by step values I need to calculate in a code way.many thanks in advance $\endgroup$
    – JSmith
    Commented Aug 17, 2021 at 11:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.