CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
+ Reply to Thread
Results 1 to 3 of 3

Thread: move in circles

  1. #1
    Join Date
    May 2007
    Posts
    148

    move in circles

    Hi,

    I want to move an object around the screen with a timer in a circle pattern(automatically). Now I can move an object from side to side and check to see if I hit the form boundary.

    The forumla of a circle is x*x+y*y=1

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    10,805

    Re: move in circles

    I'm not sure understand you 100%. Do you want to move the picture in a circular route along the screen ¿

    If that's the case, why not make it so that you don't have to worry about the form's borders in the first place.

    You could perhaps use our good friends Sin, Cos & PI here - just a suggestion.

    Or do you want the picture to move around, and when it hits the border, it bounces off of it, and proceeds to another border, for example :
    The picture moves from the Top, and hits the left border, then it proceeds to the bottom border, then the right border, and then it just repeats the pattern. I sthat what you mean ¿

    I do have a very small sample, which allows the picture to move in a spiral fashion, which might help a little bit.
    Code:
        Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    
            Dim cx As Integer
            Dim x As Integer
            Dim cy As Integer
            Dim y As Integer
    
            Dim RR As New Rectangle(10, 10, 400, 400)
    
            cx = RR.Width / 2
            cy = RR.Height / 2
    
            Dim a As Single
            Dim b As Single
            Dim i As Long
            Dim ang As Double
    
            a = 0.15 
            b = 0.15 
    
            For i = 0 To 8000 
                ang = (PI / 720) * i
                x = cx + (a * (System.Math.Cos(ang)) * (ee ^ (b * ang)))
                y = cy - (a * (System.Math.Sin(ang)) * (ee ^ (b * ang)))
                PictureBox1.Left = x
                PictureBox1.Top = y
            Next i
        End Sub

  3. #3
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,553

    Re: move in circles

    Quote Originally Posted by jagguy
    ... The forumla of a circle is x*x+y*y=1
    When you want to move objects, the more useful equation is the "parametric" equation. The parametric equation gives the x and y values in terms of a third parameter which is usually interpreted as time.

    In this case, and as HanneSThEGreaT has implied, the parametric equations of a circle are:
    x = radius * sin (2*pi*frequency*time)
    y = radius * cos (2*pi*frequency*time)
    where radius=radius of the circle, and frequency=speed of the object around the circle (in cycles/circles per second).

    Mike

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts



HTML5 Development Center

Click Here to Expand Forum to Full Width