Spreadsheet and VBA For Lissajous Curves

wellinth

Board Regular
Joined
Aug 6, 2004
Messages
58
Lissajous curves are defined by x = a*sin(theta) and y = b*sin(theta). I created a macro enabled Excel spreadsheet to draw them. I can send it to anyone with instructions on how to use it. The spreadsheet uses the VBA code below.

I'll be glad to answer any questions about this. Hope this post helps.

- Tom

Public Sub lissajous()
'Creates data points to draw a Lissajous curve
Dim a As Integer, b As Integer
Dim theta As Double, stepsize As Double, iter As Long
Dim pi2 As Double

'Read a and b from the spreadsheet
'if they are not positive then say so and exit



a = Int(Val(Cells(3, 2).Value))
b = Int(Val(Cells(4, 2).Value))



If a <= 0 Or b <= 0 Or Cells(9, 12).Value Or Cells(10, 12).Value Then

MsgBox "a and b must be positive integers. Try again.", vbExclamation

Else

'Initialize counters, steps, clear ranges and set headings.
theta = 0#
iter = 0
stepsize = Val(Cells(5, 2).Value)
pi2 = 2 * WorksheetFunction.Pi
Range("D:G").ClearContents

Cells(1, 4).Value = "Iteration"
Cells(1, 5).Value = "Step"
Cells(1, 6).Value = "Sin(" & CStr(a) & "* theta)"
Cells(1, 7).Value = "Sin(" & CStr(b) & "* theta)"


'Loop through all values in 0 to 2pi with a stepsize of stepsize
'Create data for plotting

While theta <= pi2
iter = iter + 1
Cells(1 + iter, 4).Value = iter
Cells(1 + iter, 5).Value = theta
Cells(1 + iter, 6).Value = Sin(a * theta)
Cells(1 + iter, 7).Value = Sin(b * theta)

theta = theta + stepsize

Wend

End If


End Sub
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Forum statistics

Threads
1,215,043
Messages
6,122,822
Members
449,096
Latest member
Erald

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top