# Spreadsheet and VBA For Lissajous Curves

#### wellinth

##### Board Regular
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.

- 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

'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

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

Replies
2
Views
93
Replies
1
Views
259
Replies
0
Views
158
Replies
3
Views
93
Replies
0
Views
64

1,181,673
Messages
5,931,350
Members
436,787
Latest member
ogharipour

### 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.

### Which adblocker are you using?

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

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