Advertisement
grannybat

Epitrochoid In vb

Dec 17th, 2022
1,812
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  2.     ' Set up the timer to update the position of the point on the rolling circle
  3.    Timer1.Interval = 10 ' Update the position every 10 milliseconds
  4.    Timer1.Start()
  5. End Sub
  6.  
  7. Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
  8.     ' Calculate the new position of the point on the rolling circle
  9.    Dim r As Double = 100 ' Radius of the rolling circle
  10.    Dim R As Double = 200 ' Radius of the fixed circle
  11.    Dim d As Double = 50 ' Distance between the center of the rolling circle and the point
  12.    Static theta As Double = 0 ' Angle of the rolling circle
  13.    theta += 0.1 ' Increment the angle by a small amount at each timer tick
  14.    Dim x As Double = (R + r) * Math.Cos(theta) - d * Math.Cos((R + r) * theta / r) ' X-coordinate of the point
  15.    Dim y As Double = (R + r) * Math.Sin(theta) - d * Math.Sin((R + r) * theta / r) ' Y-coordinate of the point
  16.  
  17.     ' Clear the form and draw the epitrochoid
  18.    Dim g As Graphics = Me.CreateGraphics()
  19.     g.Clear(Color.White)
  20.     g.DrawEllipse(Pens.Black, CSng(Me.Width / 2 - R), CSng(Me.Height / 2 - R), CSng(2 * R), CSng(2 * R)) ' Draw the fixed circle
  21.    g.DrawEllipse(Pens.Black, CSng(x - r), CSng(y - r), CSng(2 * r), CSng(2 * r)) ' Draw the rolling circle
  22.    g.DrawLine(Pens.Black, CSng(Me.Width / 2), CSng(Me.Height / 2), CSng(x), CSng(y)) ' Draw the line connecting the center of the fixed circle to the center of the rolling circle
  23.    g.DrawEllipse(Pens.Red, CSng(x - 5), CSng(y - 5), 10, 10) ' Draw the point on the rolling circle
  24. End Sub
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement