# Maths — how to create moving waves with Animation Nodes

I am this week learning wave equations, my very first time. I am learning those below.

No ideas? How about waves on a long strip of plane below?

With wave movement on a same plane.

# Theory

The wave equation is a second order partial differential equation, which means solving it can done by numerical integration, perhaps using the simpler Euler's Method. The one dimensional wave equation is as follows:

$$\frac{\partial^2 u}{\partial t^2} = c^2 \frac{\partial^2 u}{\partial x^2}$$

Where $$u$$ is the displacement, $$t$$ is the time, and $$x$$ is the position. The partial derivative on the right hand side is the one dimensional Laplacian. So, to compute it, we use the Discrete Laplace Operator. In particular, we can use a one dimensional convolution kernel, the kernel have the structure:

$$\begin{bmatrix} 1 \\ -2 \\ 1 \end{bmatrix}$$

Finally, to be able to solve this, we need to define the initial conditions of the system as well as its boundary conditions. That is, we have to define the initial displacement and the initial velocity. Lets assume that at $$t=0$$ the velocity was zero ($$\left.\frac{\partial u}{\partial t}\right\rvert_{t=0} = 0$$) and the displacement was zero everywhere except at a subset of the domain where it was a bell shaped curve. As for the boundary conditions, we shall use a Periodic Boundary Condition.

# Implementation

First, give the displacement, we compute the discrete laplacian using the kernel outlined above, this is easily done by vectorization as follows:

Next, given the initial velocity, lets compute the velocity after $$\delta$$ time using Euler's method as follows:

Next, lets compute the displacement given an initial displacement and the velocity using Euler's method:

Next, we make a solver loop that takes the initial velocity and displacement and reassign them at each iteration:

Finally, we define the initial conditions as discussed before and display the simulation as a circular domain, we also enable per frame caching to get real time results:

By running the animation, we get:

Which seems about right. It should be noted that this is not the most physically or mathematically accurate simulation and it is not computationally efficient either, this is just a simplified heuristic implementation to demonstrate the wave equation.

• Thank you very much for this. You are always a genius. I wish I can steal your brain and do great many things with it. Imagine all the years of learning gone inside that great brain of yours. Mar 3 '19 at 15:44
• "Where u is the displacement, t is the time, and x is the position." I know c is for constant. Now, I have learned what u is. I was previously long stuck on u. Now, I know what it is and thank you for that. I am going to look up others like laplacian, discrete laplace operator, etc. Thanks for mentioning them. Mar 3 '19 at 16:12