Algorithm for spiral

I could use an algorithm for repeatedly drawing an object in an ever-increasing spiral -- as if the object were spiraling away from its center-point until it is completely off-screen.  The object does not appear to get closer (larger), by the way.  It will be staying the same size throughout the exercise.

I know how to draw the object.  I just need a way to calculate each new origin for the object, either as a center point or corner point.

Does anyone have such a routine laying around that they would be willing to share?

Thanks,
  Ed
EdStoutAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Joe_GriffithCommented:
I think the easiest approach to this problem is to use polar coordinates.  Drawing a spiral in polar coordinates is very simple (just increment both the angle and the radius each time).  The resulting coordinates must then be converted to cartisian coordinates. The formula for converting polar coordinates to cartisian coordinates is also simple although I don't have it off the top of my head you could find it any any math book.
0
Erick37Commented:
Code example which moves Shape1 in an Archimedean spiral around the screen with a timer.

Option Explicit
'Adjust these consts to refine the spiral movement
Const ANGLE_RATE = 15
Const RADIUS_RATE = 20

Private Type POINT
    x As Long
    y As Long
End Type

Private startpt As POINT
Private angle As Long
Private r As Long
Private RAD As Single

Private Sub Form_Load()
    'Define how many radians in 360'
    RAD = 360 / (8 * Atn(1))
    startpt.x = ScaleWidth / 2
    startpt.y = ScaleHeight / 2
    Shape1.Move startpt.x, startpt.y
End Sub

Private Sub Timer1_Timer()
    Dim dx As Single
    Dim dy As Single
    'Pseudo Archimedean Spiral function
    angle = (angle + ANGLE_RATE)
    r = r + RADIUS_RATE
    'calculate new points for spiral
    dx = startpt.x + (r * Cos(angle / RAD))
    dy = startpt.y + (r * Sin(angle / RAD))
    Shape1.Move dx, dy
    If (dx < 0 - Shape1.Width) Or (dy < 0 - Shape1.Height) Then
        'Spiraled off the screen
        Timer1.Enabled = False
        Shape1.Visible = False
        Debug.Print "Done Spiraling"
    End If
End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.