Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleDraw a cycloid
Keywordscycloid, curve
CategoriesGraphics
 
This cycloid is represented by the following parametric functions as t ranges from 0 to 14 * Pi.
 
' The parametric function X(t).
Private Function X(ByVal t As Single) As Single
    X = 2000 * (27 * Cos(t) + 15 * Cos(t * 20 / 7)) / 42
End Function

' The parametric function Y(t).
Private Function Y(ByVal t As Single) As Single
    Y = 2000 * (27 * Sin(t) + 15 * Sin(t * 20 / 7)) / 42
End Function
 
In the form's Paint event handler, the program calls the DrawCurve subroutine to connect points defined by these functions.
 
' Draw the curve on the form.
Private Sub DrawCurve(ByVal start_t As Single, ByVal stop_t _
    As Single, ByVal dt As Single)
Dim cx As Single
Dim cy As Single
Dim t As Single

    cx = ScaleLeft + ScaleWidth / 2
    cy = ScaleTop + ScaleHeight / 2

    Cls
    CurrentX = cx + X(start_t)
    CurrentY = cy + Y(start_t)

    t = start_t + dt
    Do While t < stop_t
        Line -(cx + X(t), cy + Y(t))
        t = t + dt
    Loop

    Line -(cx + X(stop_t), cy + Y(stop_t))
End Sub
 
Click here to compare this code to the version used for VB .NET.

See my book Visual Basic Graphics Programming for more information on drawing cycloids and other curves normally or transformed (stretched, squashed, or rotated).

 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated