VB.net code for generating the curve is as below. Its based on the solution to a 4 bar linkage given here http://synthetica.eng.uci.edu/~mccarthy/mechanicaldesign101/McCarthyNotes-2.pdf
Dim list As New PointPairList
Dim list2 As New PointPairList
Dim list3 As New PointPairList
Dim i As Integer, m1x As Double, m1y As Double, m2x As Double, m2y As Double
Dim t As Double = 0
Dim period1 As Double = Convert.ToDouble(M1Textbox.Text)
Dim period2 As Double = Convert.ToDouble(M2Textbox.Text)
Dim period3 As Double = Convert.ToDouble(M3Textbox.Text)
Dim m1center(,) As Double = New Double(,) {{Convert.ToDouble(M1XTextbox.Text), Convert.ToDouble(M1YTextbox.Text)}}
Dim m2center(,) As Double = New Double(,) {{Convert.ToDouble(M2XTextbox.Text), Convert.ToDouble(M2YTextbox.Text)}}
Dim m3center(,) As Double = New Double(,) {{Convert.ToDouble(M3XTextbox.Text), Convert.ToDouble(M3YTextbox.Text)}}
Dim TimeStep As Double = Convert.ToDouble(TStepTextbox.Text)
Iterations = Convert.ToDouble(IterationsTextBox.Text)
For i = 0 To Iterations
Dim theta2 As Double = 2 * PI * (t / period1)
Dim k1 As Double, k2 As Double, k3 As Double, alength As Double, blength As Double, clength As Double, dlength As Double
alength = Convert.ToDouble(aLengthTextbox.Text) ' M1 radius
blength = Convert.ToDouble(bLengthTextbox.Text) 'link lengths
clength = Convert.ToDouble(cLengthTextbox.Text)
dlength = Sqrt((m2center(0, 0) - m1center(0, 0)) ^ 2 + (m2center(0, 1) - m1center(0, 1)) ^ 2) 'distance between motors
Dim radius2 As Double = 80 'M2 radius
radius2 = Convert.ToDouble(M2LengthTextbox.Text) ' M1 radius 'M2 radius
k1 = dlength / alength
k2 = dlength / clength
k3 = ((alength ^ 2) + (clength ^ 2) + (dlength ^ 2) - (blength ^ 2)) / (2 * alength * clength)
'calculate the motor positions
m1x = alength * Cos(theta2) + m1center(0, 0)
m1y = alength * Sin(theta2) + m1center(0, 1)
m2x = -radius2 * Cos(2 * PI * (t / period2)) + m2center(0, 0)
m2y = -radius2 * Sin(2 * PI * (t / period2)) + m2center(0, 1)
'calculate the linkage position
list.Add(m1x, m1y)
list2.Add(m2x, m2y)
Dim Cterm As Double = k1 - (k2 + 1) * Cos(theta2) + k3
Dim Bterm As Double = -2 * Sin(theta2)
Dim Aterm As Double = Cos(theta2) - k1 - k2 * Cos(theta2) + k3
Dim Theta4 As Double = 2 * Atan(-Bterm - Sqrt(Bterm ^ 2 - 4 * Aterm * Cterm)) + PI / 4
Dim xlink As Double = clength * Cos(Theta4) + m2x
Dim ylink As Double = clength * Sin(Theta4) + m2y
list3.Add(xlink, ylink)
Dim m3radius As Double = Sqrt((xlink - m3center(0, 0)) ^ 2 + (ylink - m3center(0, 1)) ^ 2) 'find the radius of the wheel center to the linkage
Dim wheelangle As Double = Asin((ylink - m3center(0, 1)) / m3radius)
Dim wheelRotated As Double = wheelangle + (t / period3) * 2 * PI
Dim xpen As Double = m3radius * Cos(wheelRotated) + m3center(0, 0)
Dim ypen As Double = m3radius * Sin(wheelRotated) + m3center(0, 1)
list4.Add(xpen, ypen)
If i = 0 Then
xmin = xpen
ymin = ypen
End If
If xpen < xmin Then
xmin = xpen
End If
If xpen > xmax Then
xmax = xpen
End If
If ypen < ymin Then
ymin = ypen
End If
If ypen > ymax Then
ymax = ypen
End If
xrange = Abs(xmax - xmin)
yrange = Abs(ymax - ymin)
XPointList.Add(xpen) 'generate list for pinting svg with seperating , between x and y and spaces between points
YPointList.Add(ypen)
'save as datatable for svgC
'PlotData.Columns.Add("x", GetType(Double))
'PlotData.Columns.Add("y", GetType(Double))
'PlotData.Rows.Add(xpen, ypen)
t = t + TimeStep
Next i
|