Lissajous Figures – C Program

In this post I will show you how to calculate and plot the Lissajous Curves using C and Gnuplot.
We will use the following information:
y=A\sin(n\theta + \delta)
We will create a program that calculates the values of the x and y for various \theta values and for different n and store these values in a txt file. Then just plot it using Gnuplot.
We will create two functions called ‘x’ and ‘y’, that contain the definition of x and y respectively.


********LISSAJOUS FIGURES **********
double x(double theta){
	return sin(theta);
double y(double theta, double A,double n, double delta){
	return A*sin(n*theta+delta);
	double theta;
	double A,n,delta;
	/*Loop to calculate and store data-points*/
		/*Change A, n or delta here*/

When you run the above C, it will generate a file called ‘lissajous.txt’ which would contain 2 columns of data-points.
The first column contains the ‘x’ values and the next one is for ‘y’ values.
These can be easily plotted using Gnuplot by using the following commands:

GnuPlot Command

plot 'lissajous.txt' w l


For different values of \delta ,A ; n the output looks as follows:
A=1 ; n=1 ;  \delta=\pi/4

A=1 ; n=2 ; \delta =\pi/4

A=1; n=2.5 ; \delta =\pi/4

A=1; n=2 ; \delta =\pi/2

A=1 ; n=2; \delta = \pi

A=2 ; n=2; \delta = \pi


PhD researcher at Friedrich-Schiller University Jena, Germany. I'm a physicist specializing in theoretical, computational and experimental condensed matter physics. I like to develop Physics related apps and softwares from time to time. Can code in most of the popular languages. Like to share my knowledge in Physics and applications using this Blog and a YouTube channel.
[wpedon id="7041" align="center"]

Leave a Reply

Your email address will not be published. Required fields are marked *