Since we are dealing with discrete values for both space (a grid) and time (individual
frames/time steps), we need a way to approximate these second derivatives. Essentially, given a
current grid state and previous states, we want to determine what the next state/frame should be
in time. For this, we will use the finite difference method which allows us to approximate
derivatives given a certain number of states in either time or space.
The second order finite difference formula for one dimension is
f′′(x)≈h2f(x+h)−2f(x)+f(x−h) - x is the position in space.
- h is the distance between discrete points in space.
Since we want to find the derivative of time and not space, we can adjust this formula. Instead of
looking at discrete distances left and right of a position, we can look forward and backward in time.
Now
h represents the delta timestep between states rather than between spatial grid
points. To represent this better, we can say
f(x+h) is the state in the future
ffuture(x),
f(x) is the current state
fpresent(x), and
f(x−h) is the state in the past
fpast(x). We can also say
h is the delta time between states
or
Δt.
Now we get
f′′(x)≈Δt2ffuture(x)−2fpresent(x)+fpast(x) - x is the position in space.
- h is the distance between discrete points in space.
However, this assumes we have one spatial dimension
x, so we can substitute
x in the functions for
(x,y).
f′′(x,y)≈Δt2ffuture(x,y)−2fpresent(x,y)+fpast(x,y)
Our goal is to determine the state of the function in the future at a specific
(x,y) coordinate. This means we need to solve for
ffuture(x,y) ffuture(x,y)=f′′(x,y)Δt2−fpast(x,y)+2fpresent(x,y)
Going back to our original wave propagation equation,
∂t2∂2u is represented as
f′′(x,y) in
our equation. They are the same, just difference notation and also a partial derivative because the
wave function
u(x,y,t) is a function of both space and time and thus taking the derivative
of time makes it a partial derivative instead of a complete derivative.
ffuture(x,y)=∂t2∂2uΔt2−fpast(x,y)+2fpresent(x,y)
In our simulation, we can store the present
fpresent(x,y) and past
fpast(x,y) states of our simulation in separate buffers and also keep track
of the timestep
Δt, however, in order to fully calculate the future state,
we need the second partial derivative of the wave function with respect to time
∂t2∂2u. Using the original wave propagation
function, we can substitute the right side of the equation in.
ffuture(x,y)=c2(∂x2∂2u+∂y2∂2u)Δt2−fpast(x,y)+2fpresent(x,y)