Lissajous Curves/Figures

User avatar
GeorgeMcGinn
Posts: 435
Joined: Sat Sep 10, 2016 6:37 am
My devices: IPad Pro 10.5in
IMac
Linux i386
Windows 7 & 10
Location: Venice, FL
Flag: United States of America
Contact:

Lissajous Curves/Figures

Post by GeorgeMcGinn »

In mathematics, a Lissajous curve /ˈlɪsəʒuː/, also known as Lissajous figure or Bowditch curve /ˈbaʊdɪtʃ/, is the graph of a system of parametric equations.

This program randomly generates a Lissajous curve or figure.

Definition of Lissajous figure: any of an infinite variety of curves formed by combining two mutually perpendicular simple harmonic motions, commonly exhibited by the oscilloscope, and used in studying frequency, amplitude, and phrase relations of harmonic variables (Merriam/Webster)

Origin and Etymology of lissajous figure – Jules A. Lissajous †1880 French physicist

Also known in mathematics as a parametric equation, parametric equations of a curve express the coordinates of the points of the curve as functions of a variable, called a parameter. For example, are parametric equations for the unit circle, where t is the parameter. Together, these equations are called a parametric representation of the curve.

These are commonly seen in oscilloscopes and in the 1800's used to be drawn by hand or a mechanical device called a harmonograph (a mechanical apparatus that employs pendulums to create a geometric image. The drawings created typically are Lissajous curves, or related drawings of greater complexity.)

This is my first stab in a long time at converting these formulas for such graphing scenarios such as raw output from sensors using Internet of Things, which are mostly converted and represented in graphical form.

If you turn off the graphics and change the DRAW LINE to a PRINT statement, you will see the raw values that most sensors produced, which much be converted into something with a meaning, like a graphic, often in realtime.

For this program I have created a random generator to simulate different results I may get (not accurate for sensor data, but accurate for the mathematical principle of Lissajous figures/curves) are representative) and produced the curve graph accordingly.

To get different graphs, densitites, etc., you can play around with the variables f1, f2 and c. You can also change the value of the time loop to see how the lengt of time affects the displays.

This is my first attempt in a very long time at writing such a program, and while TechBASIC is where this final product will reside, it doesn't have as robust a community to help me point out errors or show me tricks that are easier to use.

I haven't yet converted this code to TechBASIC as I first need to determine the sensor that I first choose to program for, but most graphing will be similar to each other.

Sources: https://en.m.wikipedia.org/wiki/Lissajous_curve
https://en.m.wikipedia.org/wiki/Parametric_equation
https://en.m.wikipedia.org/wiki/Harmonograph

The next is a challenge, if anyone else is interested, is called Lissajous Knots. Where Lissajous Curves are based on two points, the knots are based on 3 points, and inlucde both itegers and real numbers as parameters.

To get more information on the Lissajous Knots, check out: https://en.m.wikipedia.org/wiki/Lissajous_knot as well as other materials.

Code: Select all

/* PROGRAM: Lissajous Curves v1.0
   George McGinn
   May 30, 2017

   V1.0 – Initial Program (sizing for iPhone not working)

Definition of Lissajous figure: any of an infinite variety of curves formed by combining two mutually perpendicular simple harmonic motions, commonly exhibited by the oscilloscope, and used in studying frequency, amplitude, and phrase relations of harmonic variables (Merriam/Webster)

Origin and Etymology of lissajous figure – Jules A. Lissajous †1880 French physicist

Also known in mathematics as a parametric equation, parametric equations of a curve express the coordinates of the points of the curve as functions of a variable, called a parameter. For example, are parametric equations for the unit circle, where t is the parameter. Together, these equations are called a parametric representation of the curve.

*/


SBInit:
   GRAPHICS
   GRAPHICS CLEAR
   SHADOW OFF
   RANDOMIZE
   GRAPHICS CLEAR 1,1,1
   OPTION TEXT POS NORMAL
   SET ORIENTATION LANDSCAPE
   SET TOOLBAR OFF
   DRAW LINECAP ROUND
   DRAW SIZE 2


SBBegin:
   a=200!b=200
   f1=RND(20)!f2=RND(20)
   c=RND(100)

   X$="X=SIN(2*3.14*"&f1&"*t)"
   Y$="Y=SIN(2*3.14*"&f2&"*t+"&C&")"

   DRAW COLOR 0,0,0
   DRAW TEXT "Lissajous Curve" AT 1,5
   DRAW TEXT X$                AT 1,25
   DRAW TEXT Y$                AT 1,45

   SHADOW ON
   SHADOW OFFSET 2,2


SBLoop:
   FOR time=0 to 100000             '*** The longer the time, the more complete the pattern becomes
       t=time/20
       d=2*3.14*f1*t
       dd=sin(d)
       x=a*dd
       aa=2*3.14*f2*t+c
       cc=sin(aa)
       y=b*cc
       x=x+400
       y=300-y
       DRAW COLOR 1,0,0
       DRAW LINE x,y TO x+1,y+1
   NEXT time
George McGinn
Computer Scientist/Cosmologist/Writer/Photographer
Member: IEEE, IEEE Computer Society
IEEE Sensors Council & IoT Technical Community
American Association for the Advancement of Science (AAAS)

DrChip
Posts: 167
Joined: Wed Oct 22, 2014 3:26 pm
My devices: iPhone 4 to 6+,iPad mini to iPad air 2

Re: Lissajous Curves/Figures

Post by DrChip »

Code: Select all


/* PROGRAM: Lissajous Curves v1.0
   George McGinn
   May 30, 2017

   V1.0 – Initial Program (sizing for iPhone not working)

Definition of Lissajous figure: any of an infinite variety of curves formed by combining two mutually perpendicular simple harmonic motions, commonly exhibited by the oscilloscope, and used in studying frequency, amplitude, and phrase relations of harmonic variables (Merriam/Webster)

Origin and Etymology of lissajous figure – Jules A. Lissajous †1880 French physicist

Also known in mathematics as a parametric equation, parametric equations of a curve express the coordinates of the points of the curve as functions of a variable, called a parameter. For example, are parametric equations for the unit circle, where t is the parameter. Together, these equations are called a parametric representation of the curve.
v1.1 - iPhone sizing.
*/


SBInit:
   GRAPHICS
   GRAPHICS CLEAR
   SHADOW OFF
   RANDOMIZE
   GRAPHICS CLEAR 1,1,1
   OPTION TEXT POS NORMAL
   SET ORIENTATION LANDSCAPE
   SET TOOLBAR OFF
   DRAW LINECAP ROUND
   DRAW SIZE 2


SBBegin:
   a=100!b=100
   f1=RND(20)!f2=RND(20)
   c=RND(100)

   X$="X=SIN(2*3.14*"&f1&"*t)"
   Y$="Y=SIN(2*3.14*"&f2&"*t+"&C&")"

   DRAW COLOR 0,0,0
   DRAW TEXT "Lissajous Curve" AT 1,0
   DRAW TEXT X$                AT 1,20
   DRAW TEXT Y$                AT 1,35

   SHADOW ON
   SHADOW OFFSET 2,2


SBLoop:
   FOR TIME=0 TO 100000             '*** The longer the time, the more complete the pattern becomes
       t=TIME/20
       d=2*3.14*f1*t
       dd=SIN(d)
       x=a*dd
       aa=2*3.14*f2*t+c
       cc=SIN(aa)
       y=b*cc
       x=x+SCREEN_WIDTH()/2
       y=(SCREEN_HEIGHT()/2)-y
       DRAW COLOR x/255,y/255,x+y/255
       DRAW LINE x,y TO x+1,y+1
   NEXT TIME
Attachments
IMG_5040.PNG
IMG_5040.PNG (979.71 KiB) Viewed 6908 times
IMG_5039.PNG
IMG_5039.PNG (765.79 KiB) Viewed 6908 times

User avatar
GeorgeMcGinn
Posts: 435
Joined: Sat Sep 10, 2016 6:37 am
My devices: IPad Pro 10.5in
IMac
Linux i386
Windows 7 & 10
Location: Venice, FL
Flag: United States of America
Contact:

Re: Lissajous Curves/Figures

Post by GeorgeMcGinn »

Dr. Chip, I like the multi-color.

There is one thing I could not code. I have an iPad and when I inserted the code from rbytes it did not work.

I could not get it to simulate running on an iPhone.

If anyone can accomplish that (I do not yet have an iPhone, otherwise I could develop a version for it) please update it here.

It will be great to have as I or anyone who accepted the challenge to write a program to produce the Lissajous Knots!

George.
George McGinn
Computer Scientist/Cosmologist/Writer/Photographer
Member: IEEE, IEEE Computer Society
IEEE Sensors Council & IoT Technical Community
American Association for the Advancement of Science (AAAS)

User avatar
Dutchman
Posts: 848
Joined: Mon May 06, 2013 9:21 am
My devices: iMac, iPad Air, iPhone
Location: Netherlands
Flag: Netherlands

Re: Lissajous Curves/Figures

Post by Dutchman »

Where are the sliders to change the parameters :?: :lol:

DrChip
Posts: 167
Joined: Wed Oct 22, 2014 3:26 pm
My devices: iPhone 4 to 6+,iPad mini to iPad air 2

Re: Lissajous Curves/Figures

Post by DrChip »

Hi George,

It runs fine on a iPhone. I just added the screen width and height to the code. Small change but it works. :)

User avatar
GeorgeMcGinn
Posts: 435
Joined: Sat Sep 10, 2016 6:37 am
My devices: IPad Pro 10.5in
IMac
Linux i386
Windows 7 & 10
Location: Venice, FL
Flag: United States of America
Contact:

Re: Lissajous Curves/Figures

Post by GeorgeMcGinn »

Hi Ton,

I couldn't sleep last night and discovered this while doing research, so I barely had time to finish the program.

Ricardo would also find these interesting as they were discovered using sound vibrating against glass. One source says "Lissajous (pronounced LEE-suh-zhoo) figures were discovered by the French physicist Jules Antoine Lissajous. He would use sounds of different frequencies to vibrate a mirror. A beam of light reflected from the mirror would trace patterns which depended on the frequencies of the sounds. Lissajous' setup was similar to the apparatus which is used today to project laser light shows. (From the math.com website – http://www.math.com/students/wonders/li ... ajous.html).

If I do not get around to creating sliders, feel free to add them!!! :D :D :D I've yet to use these statements in a program, so it's on my to-do list. And when you look at the formulas that actually create these, there may be a need for more than a few sliders. But I will look into them once I can see how to code the knots, where you can see a line placed on top of one and then below a line right next to it.

But I was figuring on using Ricardo's flashing code and make the lines flash, merge Dr. Chip's random color to change the color with each flash ;)

Dr. Chip – I am assuming the code you posted is the code that allows it to run fine on an iPhone? If so, thanks and I will add it to mine. If not, then post the code, as I read the code and I saw where you incorporated the screen width and height, but also randomized the color selection. Just want to make sure I grab the right code as there was no other comment about the changes made.

Thanks.

Dutchman wrote:
Wed May 31, 2017 10:07 am
Where are the sliders to change the parameters :?: :lol:
George McGinn
Computer Scientist/Cosmologist/Writer/Photographer
Member: IEEE, IEEE Computer Society
IEEE Sensors Council & IoT Technical Community
American Association for the Advancement of Science (AAAS)

User avatar
GeorgeMcGinn
Posts: 435
Joined: Sat Sep 10, 2016 6:37 am
My devices: IPad Pro 10.5in
IMac
Linux i386
Windows 7 & 10
Location: Venice, FL
Flag: United States of America
Contact:

Re: Lissajous Curves/Figures

Post by GeorgeMcGinn »

Hi Dr. Chip,

Thanks for the updates. I am assuming it is in the code you posted, so I will load it and as you added along with the adjustments for SW & SH, but color or hue.

The current DRAW LINE has a from/to parameter, or once the starting point has been established, you can just provide the TO parameter.

However, the other component is HUE which I see you addressed in the DRAW COLOR statement.

Here is a table that simplifies the parameters that should go into drawing a proper Lissajous Curve/Figure, which includes HUE and Line thickness, which I defaulted to a "2" for now.

Here's the table from the website quoted in my last post:

Explanation of Readout Values
xFreq This is the number of horizontal cycles for each frame of the plot.
yFreq This is the number of vertical cycles for each frame of the plot.
hueFreq This is the number of hue cycles for each frame of the plot. Each hue cycle represents a complete spectrum of colors.
Samples This is the number of line segments which will be used to draw each frame of the plot. Increasing this number will make the curves appear smoother. Decreasing this number will exacerbate the aliasing in the plot (making it look more like string art than a mathematical curve).

Thanks for the update. I hope others add to this as I find this math fascinating, as with the knots program code to be written next, three parameters are needed instead of just the 2 used in the curves/figure program.

The image attached was produced with POV code for Windows, which I have the code but not the compiler/interpreter to run it. So I am not sure SmartBASIC can create the 3D-looking knot.

George
Three Twisted (5.2) Lissajous Knnot
Three Twisted (5.2) Lissajous Knnot
IMG_1556.PNG (160.18 KiB) Viewed 6895 times

DrChip wrote:
Wed May 31, 2017 10:19 am
Hi George,

It runs fine on a iPhone. I just added the screen width and height to the code. Small change but it works. :)
George McGinn
Computer Scientist/Cosmologist/Writer/Photographer
Member: IEEE, IEEE Computer Society
IEEE Sensors Council & IoT Technical Community
American Association for the Advancement of Science (AAAS)

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: Lissajous Curves/Figures

Post by rbytes »

Dr. Chip, is your code supposed to produce the color variations shown in your examples? I am only getting black and white images.

George, you won't get as realistic 3D shading as your rendered image, but you could still create get an impression of 3D.

When you draw the curves, start with black, increase it gradually to white for the first 1/3 of the iterations, stay white for the second third, and then gradually reduce intensity to black for the last 1/3. This will create a cylindrical look.
The only thing that gets me down is gravity...

User avatar
GeorgeMcGinn
Posts: 435
Joined: Sat Sep 10, 2016 6:37 am
My devices: IPad Pro 10.5in
IMac
Linux i386
Windows 7 & 10
Location: Venice, FL
Flag: United States of America
Contact:

Re: Lissajous Curves/Figures

Post by GeorgeMcGinn »

Thanks bud -

I'm going to put this up on Rosetta. Right now there are no pages on Lissajous curves so I am going to create it and add the SmartBASIC code.

Also, a month ago I received the Hercules Z-390 mainframe emulator software for my Windows PC and I now have 12 mainframe languages, so I may write a COBOL, PL/I, ASSEMBLER, ALGOL, FORTRAN and put them all up at once.

However, I think Scott (remember him?) set up the SmartBASIC page up incorrectly. I know because I copied the TechBASIC page after his and someone at Rosetta deleted the page and recreated it. Now my programs show up on the page.

None of the SmartBASIC programs I wrote are showing up on its page, and I wrote quite a few, so if I can't get that person who just yesterday fixed my page, I will try and recreate it myself. My only fear is many of you submitted a ton of code and I'd hate to see it disappear if I try and fix it.

George.
rbytes wrote:
Wed May 31, 2017 2:01 pm
Dr. Chip, is your code supposed to produce the color variations shown in your examples? I am only getting black and white images.

George, you won't get as realistic 3D shading as your rendered image, but you could still create get an impression of 3D.

When you draw the curves, start with black, increase it gradually to white for the first 1/3 of the iterations, stay white for the second third, and then gradually reduce intensity to black for the last 1/3. This will create a cylindrical look.
George McGinn
Computer Scientist/Cosmologist/Writer/Photographer
Member: IEEE, IEEE Computer Society
IEEE Sensors Council & IoT Technical Community
American Association for the Advancement of Science (AAAS)

Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Re: Lissajous Curves/Figures

Post by Henko »

graphics ! graphics clear .8,.8,.8
d=56 ! option angle degrees
fill color 1,1,1 ! refresh off
loop:
phaseX+=5 ! phaseY+=10
for i=0 to 2 ! for j=0 to 1
box(d+j*(300+d),20+i*320,300,300,.5,.5,15)
draw color 1,0,0 ! draw size 1
for a=0 to 720 step 2
x=9*sin((1+2*i)*a+phaseX) ! y=9*cos((1+1.5*j)*a+phaseY)
if a=0 then ! xo=x ! yo=y ! endif
draw_it(xo,yo,x,y) ! xo=x ! yo=y
next a
next j ! next i
refresh
goto loop

def box(xlu,ylu,width,height,xm,ym,scale)
org_x=xlu+xm*width ! org_y=ylu+(1-ym)*height
xrl=xlu+width ! yrl=ylu+height
draw size 4
draw color 0,0,0
fill rect xlu-4,ylu-4 to xrl+4,yrl+4
draw rect xlu-4,ylu-4 to xrl+4,yrl+4
draw size 1 ! draw alpha .2
step=scale
for x=org_x to xrl step step ! draw line x,ylu to x,yrl ! next x
for x=org_x to xlu step -step ! draw line x,ylu to x,yrl ! next x
for y=org_y to yrl step step ! draw line xlu,y to xrl,y ! next y
for y=org_y to ylu step -step ! draw line xlu,y to xrl,y ! next y
draw color 0,0,1 ! draw size 2 ! draw alpha 1
draw line xlu,org_y to xrl,org_y
draw line org_x,ylu to org_x,yrl
end def

def draw_it(xs,ys,xe,ye)
x1=box.org_x+box.scale*xs ! y1=box.org_y-box.scale*ys
x2=box.org_x+box.scale*xe ! y2=box.org_y-box.scale*ye
draw line x1,y1 to x2,y2
end def

Post Reply