[Webinar] Streamline your web hosting managementRegister Today

x
Solved

# Algorithm for spiral

Posted on 1999-12-21
Medium Priority
2,910 Views
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
0
Question by:EdStout

LVL 7

Expert Comment

ID: 2298612
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

LVL 32

Accepted Solution

Erick37 earned 400 total points
ID: 2298626
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

Private Type POINT
x As Long
y As Long
End Type

Private startpt As POINT
Private angle As Long
Private r As Long

'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)
'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

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
###### Suggested Courses
Course of the Month8 days, 13 hours left to enroll