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
 
 
 
 
 
TitleGraph a lemniscate curve in polar coordinates
Keywordsgraph, polar coordinates, lemniscate
CategoriesGraphics
 
This program graphs the equation r = Sqr(Cos(t) * Sin(t)). It starts by setting ScaleMode so the coordinates fit nicely on the PictureBox.

Next the program lets t (theta) run over the values needed for the curve in small increments. For this equation, 0 <= t <= 2 * PI. It uses the value of t to calculate r.

Next the program converts the polar coordinates (r, t) into cartesian coordinates (x, y) where:

    x = r * Cos(t)
    y = r * Sin(t)

The program connects the points to draw the curve.

 
Private Sub Form_Load()
Const PI = 3.14159265
Dim x As Single
Dim y As Single
Dim r As Single
Dim t As Single
Dim dt As Single

    ' Set a convenient scale.
    picGraph.AutoRedraw = True
    picGraph.ScaleLeft = -1.1
    picGraph.ScaleWidth = 2.2
    picGraph.ScaleTop = 1.1
    picGraph.ScaleHeight = -2.2

    ' Draw axes.
    picGraph.Line (-2, 0)-(2, 0), vbBlue
    For x = -1 To 1
        picGraph.Line (x, -0.1)-(x, 0.1), vbBlue
    Next x
    picGraph.Line (0, -2)-(0, 2), vbBlue
    For y = -1 To 1
        picGraph.Line (-0.1, y)-(0.1, y), vbBlue
    Next y

    ' Draw the parametric curve.
    t = 0
    dt = PI / 100
    picGraph.CurrentX = 0
    picGraph.CurrentY = 0
    Do While t <= 2 * PI
        r = Cos(t) * Sin(t)
        If r >= 0 Then
            r = Sqr(r)
            x = r * Cos(t)
            y = r * Sin(t)
            picGraph.Line -(x, y)
        End If
        t = t + dt
    Loop
    picGraph.Line -(0, 0)
End Sub
 
A lemniscate is a figure-eight.
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated