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 curve in polar coordinates
Keywordsgraph, polar coordinates
CategoriesGraphics
 

This program graphs the equation r = 2 * Sin(5 * 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.Scale (-2, 2)-(2, -2)

    ' Draw axes.
    picGraph.Line (-2, 0)-(2, 0), vbBlue
    For x = -2 To 2 Step 0.5
        picGraph.Line (x, -0.1)-(x, 0.1), vbBlue
    Next x
    picGraph.Line (0, -2)-(0, 2), vbBlue
    For y = -2 To 2 Step 0.5
        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 = 2 * Sin(5 * t)
        x = r * Cos(t)
        y = r * Sin(t)
        picGraph.Line -(x, y)
        t = t + dt
    Loop
    picGraph.Line -(0, 0)
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated