|
-
Jul 18th, 2001, 09:31 PM
#1
Thread Starter
Addicted Member
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-
-
Jul 19th, 2001, 12:04 AM
#2
Fanatic Member
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:
Option Explicit
Const Pi As Double = 3.14159265358979
Dim dblLength As Double
Dim dblAngle As Double
Private Sub Form_Click()
tmrRotate.Enabled = Not tmrRotate.Enabled
End Sub
Private Sub Form_Load()
Me.ScaleMode = vbPixels
tmrRotate.Interval = 100
With linLine
'this is just the length of the line, from the distance formula you're most likely familiar with
dblLength = Sqr(((.X2 - .X1) ^ 2) + ((.Y2 - .Y1) ^ 2))
End With
End Sub
Private Sub tmrRotate_Timer()
dblAngle = dblAngle + ((2 * Pi) / 360)
With linLine
.X1 = .X2 + (dblLength * Cos(dblAngle))
.Y1 = .Y2 + (dblLength * Sin(dblAngle))
End With
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 
-
Jul 19th, 2001, 12:34 AM
#3
Thread Starter
Addicted Member
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-
-
Jul 19th, 2001, 12:56 AM
#4
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|