Results 1 to 4 of 4

Thread: Angles in vb.correct = false!

  1. #1

    Thread Starter
    Addicted Member krah's Avatar
    Join Date
    Jan 1999
    Location
    Arkansas, her hyuck!
    Posts
    163

    Cool Angles in vb.correct = false!

    Help me out here- do angles that go from 0 to 6.28 go clockwise or counter-clockwise in vb? It seems to be backwards from traditional math. Were my teachers on crack? You tell me. Any other info on the subject is greatly appreciated.
    Is it tired in here or is it just me?

    Ryan Williams
    -Using Vb6-

  2. #2
    Fanatic Member Kaverin's Avatar
    Join Date
    Oct 2000
    Posts
    930
    There is no real orientation to the angles if you want to be technical about it, since you can define your own reference. You can see it though if you have something rotating based on some trig. It's because of how the coordinate system of a window is done, with down being the positive y axis rather than the negative one, so quadrants I and II are flipped with III and IV. In that regard though, it will appear to be clockwise. VB does use the standard reference in how it "starts" out though, by anchoring angles to the positive x axis. If you want to see what I'm talking about, put this into a project. It's just a line that will move like a clock hand. As the angle increases from 0, you'll see it move clockwise. The line starts in the standard position. You can just stick the line anywhere on the form, but give it room to rotate around. The end at X2,Y2 is the end that will be fixed, and X1,Y1 will be moving. The line is named linLine, and you need a timer named tmrRotate. Click on the form to start/stop the timer.
    VB Code:
    1. Option Explicit
    2. Const Pi As Double = 3.14159265358979
    3. Dim dblLength As Double
    4. Dim dblAngle As Double
    5. Private Sub Form_Click()
    6.    tmrRotate.Enabled = Not tmrRotate.Enabled
    7. End Sub
    8. Private Sub Form_Load()
    9.    Me.ScaleMode = vbPixels
    10.    tmrRotate.Interval = 100
    11.    With linLine
    12.       'this is just the length of the line, from the distance formula you're most likely familiar with
    13.       dblLength = Sqr(((.X2 - .X1) ^ 2) + ((.Y2 - .Y1) ^ 2))
    14.    End With
    15. End Sub
    16. Private Sub tmrRotate_Timer()
    17.    dblAngle = dblAngle + ((2 * Pi) / 360)
    18.    With linLine
    19.       .X1 = .X2 + (dblLength * Cos(dblAngle))
    20.       .Y1 = .Y2 + (dblLength * Sin(dblAngle))
    21.    End With
    22. End Sub
    Isn't trig lovely .
    Last edited by Kaverin; Jul 19th, 2001 at 12:14 AM.
    I'm baaaack...
    VB5 Professional Edition, VC++ 6
    Using a 1 gHz Thunderbird, 256 mb RAM, 40 gb HD system with Win98se

    I feel special because I finally figured out how to loop midis: Post link
    I'm a fanatic too

  3. #3

    Thread Starter
    Addicted Member krah's Avatar
    Join Date
    Jan 1999
    Location
    Arkansas, her hyuck!
    Posts
    163

    Thumbs up

    Thank you thank you thank you! It makes such perfect sense now. I didn't even think about the fact that since the origin had been moved up they would flip the quadrants. I'm off now to fix my program. You are my savior oh wise one! Gracias!
    Is it tired in here or is it just me?

    Ryan Williams
    -Using Vb6-

  4. #4
    Fanatic Member Kaverin's Avatar
    Join Date
    Oct 2000
    Posts
    930
    Trig is my buddy It took me a while to figure this out on my own back when I first encountered it too. I thought I was going nuts because the sacred reference seemed to be discarded .
    I'm baaaack...
    VB5 Professional Edition, VC++ 6
    Using a 1 gHz Thunderbird, 256 mb RAM, 40 gb HD system with Win98se

    I feel special because I finally figured out how to loop midis: Post link
    I'm a fanatic too

Posting Permissions

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



Click Here to Expand Forum to Full Width