# Applying velocity Verlet algorithm

I want to implement a simple particules system using the velocity form of the Verlet algorithm as integrator.

Initial conditions at $t=0$ for a given particule $p$:

• mass: $m$
• position: $\overrightarrow x(t=0) = \overrightarrow x_0$
• velocity: $\overrightarrow v(t=0) = \overrightarrow v_0$
• forces applied to it: $\overrightarrow F(t=0) = \overrightarrow F_0$

Algorithm's recipe says:

1. Calculate: $\overrightarrow v(t+\frac{1}{2}\Delta t) = \overrightarrow v(t) + \frac{1}{2}\overrightarrow a(t)\Delta t$
2. Calculate: $\overrightarrow x(t+\Delta t) = \overrightarrow x(t) + \overrightarrow v(t+\frac{1}{2}\Delta t) \Delta t$
3. Derive: $\overrightarrow a(t+\Delta t)$ from the interaction potential using $\overrightarrow x(t+\Delta t)$
4. Calculate: $\overrightarrow v(t+\Delta t) = \overrightarrow v(t + \frac{1}{2}\Delta t) + \frac{1}{2}\overrightarrow a(t+\Delta t)\Delta t$

Let's apply it in order to find $\overrightarrow x(t=1)$ and $\overrightarrow v(t=1)$, so with $\Delta t = 1$:

1. $\overrightarrow v(0+\frac{1}{2}1) = \overrightarrow v(0) + \frac{1}{2}\overrightarrow a(0)1 = \overrightarrow v_0 + \frac{1}{2}\frac{\overrightarrow F_0}{m}$ [OK using Newton's second law]
2. $\overrightarrow x(0+1) = \overrightarrow x(0) + \overrightarrow v(0+\frac{1}{2}1) 1 = \overrightarrow x_0 + (1.)$ [OK using previous result (1.)]
3. ???
4. $\overrightarrow v(0+1) = \overrightarrow v(0 + \frac{1}{2}1) + \frac{1}{2}\overrightarrow a(0+1)1 = (1.) + \frac{1}{2}(3.)$ [OK using (1.) and (3.)]

--

So I'm stuck with (3.)

I have to calculate $\overrightarrow a(0+1)$ but I don't know how... I can't apply Newton's second law here since I don't know $\overrightarrow F(t=1)$. Algorithm says "from the interaction potential using (1.)" but I don't understand what it means...

Can you help?

Thank you

-
–  leonbloy Aug 16 '12 at 18:25

I think you all your steps are correct, I would suggest adding units though, otherwise adding $\vec{x}$ and $\vec{v}$ can be misleading.

For step 3. You can just calculate $a = F/m$, where $F$ can either be gravitation $F=m g$, so it does not depend on $x$, or for example for a spring dependent on $x$, so $F = -k x$, here you need the next position from step 2.

-
For step 3., I'm at $t=0$ and I'm calculating $\overrightarrow a(t+1)$ eg $\overrightarrow a(1)$. I only know $\overrightarrow F_{t=0}$ not $\overrightarrow F_{t=1}$ so like I was saying, I can't apply Newton's second law $\overrightarrow a(1) = \overrightarrow F_1/m$ since I don't have $\overrightarrow F_1$... –  abernier Aug 17 '12 at 9:13
It depends on your potential, so as an example for a spring $F(1) = -k x(1)$, which you can use to calculate $a(1)$. The next position $x(1)$ comes from your second step. –  Alexander Aug 17 '12 at 13:42
But what if I can't have $F(1)$ for example in my case $F(t)$ depends on a user's interaction, eg: drag with mouse — so I cannot predict $F(1)$ when at $t = 0$ It's not a spring, or maybe it could be, but dragged by a crazy user with a mouse in his hand so I cannot have $k$ in advance. –  abernier Aug 17 '12 at 23:15
@abernier: You always need to know the conditions beforehand, so I think there is no way your simulation lags 1 frame behind the user input. Maybe our game development partner site has more input on this. –  Alexander Aug 18 '12 at 19:19

To integrate your equation, you need to know the force law: F(x)=-dU(x)/dx F(x)= (U(x)-U(x+Dx))/Dx

What kind of potential to you deal with ?

-
What $U$ is for ? –  abernier Aug 17 '12 at 9:18
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 1, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.8639324903488159, "perplexity": 719.6648023926195}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 5, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2014-42/segments/1414637897717.20/warc/CC-MAIN-20141030025817-00204-ip-10-16-133-185.ec2.internal.warc.gz"}