[ Prev | Index | Next ]
Japanese English
Now Loading...
Download
Please download on PC (not smartphone) and extract the ZIP file. Then double-click VCSSL.bat (batch file) to execute for Microsoft® Windows®, or execute VCSSL.jar (JAR file) on the command line for Linux® and other OSes.
For details, see How to Use.
You are free to use and modify this program and material, even for educational or commercial use. » Details

Wave Interference Animation (Two Sine Waves on a Line)

This is a simple simulator developed in VCSSL to visualize the interference between sine waves traveling along a one-dimensional line.

- Table of Contents -

In the previous article, we focused on the animation of a single sine wave. This article continues from there. If you're not yet familiar with what a sine wave is, please refer to that article first. Here, we'll superimpose two sine waves and animate how they interfere with each other.

[ Related Article ]

Sponsored Link


How to Use

Download and Extract

At first, click the "Download" button at the above of the title of this page by your PC (not smartphone). A ZIP file will be downloaded.

If you are using Windows, right-click the ZIP file and choose "Properties" from the menu, and enable "Unblock" checkbox at the right-bottom (in the line of "Security") of the properties-window. Otherwise, when you extract the ZIP file or when you execute the software, security warning messages may pop up and the extraction/execution may fail.

Then, please extract the ZIP file. On general environment (Windows®, major Linux distributions, etc.), you can extract the ZIP file by selecting "Extract All" and so on from right-clicking menu.

» If the extraction of the downloaded ZIP file is stopped with security warning messages...

Execute this Program

Next, open the extracted folder and execute this VCSSL program.

For Windows

Double-click the following batch file to execute:

VCSSL__Double_Click_This_to_Execute.bat

For Linux, etc.

Execute "VCSSL.jar" on the command-line terminal as follows:

cd <extracted_folder>
java -jar VCSSL.jar

» If the error message about non-availability of "java" command is output...

After Launching the Program

When the program starts, you'll be asked whether to input numerical values for the wave parameters. If you don't have a specific need like "setting the wavelength to exactly this value," it's fine to just skip this by choosing "No."

Then, two windows will appear: a graph window and a parameter setting window.

Graph Window and Setting Window

In the graph window, the sine waves are animated.

The red and blue curves represent the two individual waves (Wave A and Wave B) to be superimposed. The green curve represents the resulting composite wave formed by their interference. In the parameter setting window, you can adjust values such as the amplitude, wavelength, and period independently for each wave using sliders.

Closing either window will terminate the program.

Note for users who have difficulty distinguishing red and green:

If it's hard to tell apart Wave A (red) and the composite wave (green), you can change their colors freely by selecting Edit > Set Color from the menu at the top of the graph window.

In the color settings window, Series No.1 corresponds to Wave A, No.2 to Wave B, and No.3 to the composite wave. For example, if you set No.3 to "BLACK", the composite wave will be drawn in black instead of green.

Color Settings Result

Concept Overview

When multiple waves are superimposed, the resulting wave often takes on a shape (and motion) that is quite different from the original waves. This phenomenon is called interference.

For example, sine waves follow the shape of the sin function. When two sine waves with slightly different wavelengths are superimposed, a distinctive pattern appears: areas of large amplitude and small amplitude (even close to zero) alternate along the x-axis. The result looks like a distorted sine wave, as shown by the green curve below:

Figure of Different Wavelength
( Wave A: A=1.0, ƒÉ=0.35, T=1.0     Wave B: A=1.0, ƒÉ=0.4, T=1.0 )

If the periods are different instead, the amplitude changes over time even at the same position along the x-axis. This is known as a beat phenomenon.

Figure of Different Period
( Wave A: A=1.0, ƒÉ=0.4, T=2.0     Wave B: A=1.0, ƒÉ=0.4, T=1.0 )

When both wavelength and period differ, you can observe the unique pattern along the x-axis shifting over time.

Figure of Different Wavelength and Period
( Wave A: A=1.0, ƒÉ=0.35, T=1.0     Wave B: A=1.0, ƒÉ=0.4, T=0.5 )

What's especially interesting is that the pattern of amplitude variation (the envelope) and the distorted sine waves within it generally move in different directions and at different speeds. The speed of the envelope is called the group velocity, while the speed of the inner waves is called the phase velocity.

The phase velocity also applies to single sine waves -- it's simply the speed of the wave itself. For composite waves made from two similar sine waves, the phase velocity is almost the same as that of the originals.

In contrast, the group velocity depends on the ratio of the differences in wavelength and period (or, equivalently, the difference in wave number and angular frequency). If you superimpose a continuous spectrum of many waves with varying wavelengths and periods, the ratio becomes a derivative instead of a simple difference.


Sponsored Link


Code

This program is written in VCSSL.

Here, we'll briefly explain the contents of the code. Since VCSSL uses a simple C-like syntax, it should be relatively easy to read for anyone who has experience with C or similar languages.

If you'd like to customize this program -- such as changing the graph range or making other modifications -- you can open the source file SineWave.vcssl in any text editor and edit it directly. Since VCSSL is a scripting language, no compiler or external software is needed: simply modify the code and run it.

Full Code

Let's first take a look at the entire code:

That's it. It's a short program, a bit over 300 lines. Most of the logic is already explained in the inline comments within the code itself, but in this section, we'll walk through the main parts in more detail.

This program is largely based on the code from the previous article, Sine Wave Animation. The main difference is that now we're working with two sine waves instead of one, and the code has been slightly extended to accommodate that.

So if you're new to the basic structure, we recommend reviewing the earlier code first.

Below, we'll focus on the parts that have changed since the previous version.

Variable Declarations

At the beginning of the program, variables are declared-just like in the previous version. The key difference is that now we have two waves, so parameters and slider controls are prepared separately for Wave A and Wave B.

One notable change is the arrays used to store coordinate data for plotting. Previously, we only needed 1D arrays, but now we use 2D arrays:

This is because we now need to pass multiple data series to the graph. The first dimension (the leftmost one) corresponds to the different wave series: Wave A, Wave B, and the composite wave, totaling three.

The second dimension is for the individual data points within each wave, same as before. Each series contains N points, which are connected by lines in the graph.

Assigning Wave Data and Plotting in the main Function

Now let's look at the part inside the animation loop in the main() function where wave data is calculated and passed to the graph:

This block is inside the animation loop, so you can think of it as drawing one frame of the graph at a specific time "t". By incrementally increasing t and repeatedly running this loop -- like a flipbook -- the graph appears animated.

For Wave A and Wave B, the logic is essentially the same as in the previous program: We compute the Y-value of a sine wave at each small step along the X-axis using the formula:

\[ y = A \sin 2 \pi \bigg( \frac{t}{T} - \frac{x}{\lambda} \bigg) \]

Then we store those X and Y values into arrays. The graphing software connects the dots automatically to form the wave shapes.

The next part is the composite wave, which we calculate by simply adding the Y-values of Wave A and Wave B at each point. It may seem almost too simple, but for typical physical waves, this approach works accurately thanks to the principle of superposition, which holds well in everyday scenarios.

In other words, this program assumes a perfectly ideal case where the principle of superposition holds precisely.

Note: Of course, there are situations where superposition doesn't hold this simply. In such cases, you can't just add the wave values directly. Instead, you'd typically start with a predefined composite wave and use numerical methods to solve the time-evolution differential equations to simulate how it evolves over time.

Other Parts

The rest of the code is a straightforward extension of the previous version. Sliders and controls are added for the two separate waves, but no major structural changes were made.

That's all for the code explanation!

License

The license of this VCSSL / Vnano code (the file with the extension ".vcssl" / ".vnano") is CC0 (Public Domain), so you can customize / divert / redistribute this VCSSL code freely.

Also, if example code written in C/C++/Java are displayed/distributed on Code section of this page, they also are distributed under CC0, unless otherwise noted.



Sponsored Link



Japanese English
[ Prev | Index | Next ]
Wave Interference Animation (Two Sine Waves on a Line)

Interactive simulation of wave interference between two 1D sine waves.
Circular Wave Animation

Draws the circular wave as 3D animation, under the specified wave parameters.
Sine Wave Animation

Interactive simulator for animating sine waves with adjustable parameters.
Vnano | Solve The Lorenz Equations Numerically

Solve the Lorenz equations, and output data to plot the solution curve (well-known as the "Lorenz Attractor") on a 3D graph.
Index
[ Prev | Index | Next ]
Wave Interference Animation (Two Sine Waves on a Line)

Interactive simulation of wave interference between two 1D sine waves.
Circular Wave Animation

Draws the circular wave as 3D animation, under the specified wave parameters.
Sine Wave Animation

Interactive simulator for animating sine waves with adjustable parameters.
Vnano | Solve The Lorenz Equations Numerically

Solve the Lorenz equations, and output data to plot the solution curve (well-known as the "Lorenz Attractor") on a 3D graph.
News From RINEARN
* VCSSL is developed by RINEARN.

Released: Latest Version of VCSSL with Fixes for Behavioral Changes on Java 24
2025-04-22 - VCSSL 3.4.50 released with a fix for a subtle behavioral change in absolute path resolution on network drives, introduced in Java 24. Details inside.

Released the Latest Versions of RINEARN Graph and VCSSL - Now Supporting Customizable Tick Positions and Labels!
2024-11-24 - Starting with this update, a new "MANUAL" tick mode is now supported, allowing users to freely specify the positions and labels of ticks on the graph. We'll explain the details and how to use it.

Released Exevalator 2.2: Now Compatible with TypeScript and Usable in Web Browsers
2024-10-22 - The open-source expression evaluation library, Exevalator, has been updated to version 2.2. It now supports TypeScript and can be used for evaluating expressions directly in web browsers. Explains the details.

Behind the Scenes of Creating an Assistant AI (Part 1: Fundamental Knowledge)
2024-10-07 - The first part of a series on how to create an Assistant AI. In this article, we introduce the essential knowledge you need to grasp before building an Assistant AI. What exactly is an LLM-based AI? What is RAG? And more.

Launching an Assistant AI to Support Software Usage!
2024-09-20 - We've launched an Assistant AI that answers questions about how to use RINEARN software and helps with certain tasks. Anyone with a ChatGPT account can use it for free. We'll explain how to use it.

Software Updates: Command Expansion in RINEARN Graph, and English Support in VCSSL
2024-02-05 - We updated our apps. This updates include "Enhancing the Command-Line Features of RINEARN Graph" and "Adding English Support to VCSSL." Dives into each of them!

Inside the Repetitive Execution Speedup Impremented in Vnano Ver.1.1
2024-01-17 - Delves into the update in Vnano 1.1 from a developer's viewpoint, providing detailed insights into the specific improvements made to the internal structure of the script engine.

Scripting Engine Vnano Ver.1.1 Released: Dramatic Speed Improvement for Repetitive Executions of the Same Content
2023-12-22 - Released the Vnano script engine Ver.1.1. In this version, we've made significant enhancements in processing speed by reducing the overhead of handling requests. Explains the details.