|
-
Aug 8th, 2002, 10:49 PM
#1
Thread Starter
Member
angles in vb6
vb6 is in radian format isn't it? I mean, if it isn't, someone tell me why my line isn't going in a circle here....
Basically, I have a line whose first point is in the middle of a picture box. The second (which should work when the development tool is in angle format) is as follows:
pic1.scalewidth/2 + (radius * Math.Sin(angle)), pic1.scaleheight/2 + (radius * Math.Cos(angle)))
This doesn't work. It displays the line in a spinning fashion, but in a 60 or so degree interval. Now, I know there is a conversion for this sort of thing involving 360 and pi, but I can't quite remember how to implement it here.
**NOTE** if there is a simple option to switch vb to angles from radians, then please tell me, if not, read on.
Let's take part of that code out. I took the 'Math.Sin(angle)' bit and fooled around with it. I changed it to 'Math.Sin(angle / pi * 180).' This gives it the right effect, but the angles are slightly off... what I mean is that the line will spin counterclockwise around the first point as the angle variable increases, but when I had it stop at 360º, the line depicts more of a 350º angle. I used 3.14159 as pi... Is there a vb pi function I am not aware of that would help this situation, or am I just trying to convert this wrong? Someone who understands the questions here, PLEASE HELP!! thanks :P
XX The Signature of the Gods XX
-
Aug 8th, 2002, 11:07 PM
#2
Frenzied Member
ALL math functions on a computer use radians. There isnt a way to change that, but to convert from degrees to radians, simply multiply the degrees by (pi / 180). To convert from radians to degrees, multipy by (180 / pi).
Z.
-
Aug 9th, 2002, 12:10 AM
#3
Thread Starter
Member
well first off, thank you for replying :P i tried both of those and i think you got it backwards, but i got what i was looking for. Yet there is still that same problem. Ill show you.
This will only take a second. Just make a picbox named pic1, set scalemode to pixels, and have it 557x373 (in pixels), and autoredraw couldnt hurt. Next make a timer named tmr1, set its interval to 10. One last thing, a label named lbl1, big enough for like 10 or so characters. Then add this code to the form:
VB Code:
Option Explicit
Dim angle, pi As Integer
Private Sub form_load()
pi = 3.14159
End Sub
Private Sub tmr1_Timer()
'pic1.Cls
If angle <= 359 Then
pic1.Line (278.5, 186.5)-(278.5 + 100 * Math.Sin(angle * (pi / 180)), 186.5 + 100 * Math.Cos(angle * (pi / 180))), vbBlack
angle = angle + 1
End If
'If angle >= 360 Then angle = 0
lbl1.Caption = "Angle = " & angle
End Sub
Run it and you will see (if you took the 2 minutes to make this little proggy up) that it stops when the angle variable is 360, yet there is only about 350º of a circle drawn. HELP!! :?
XX The Signature of the Gods XX
-
Aug 9th, 2002, 12:36 AM
#4
Frenzied Member
You need to draw a line between the start and end points of your arc to get a full circle.
Z.
-
Aug 9th, 2002, 06:17 AM
#5
Lively Member
just a little comment
i think it isn't realy helpful to declare pi as an integer and then set it to 3.14159 because this results in becoming just 3. declare it as single and set it to 3.141593 if you want if more precisely than just 3
cYa
-=R0ckAw4Y=-
-
Aug 9th, 2002, 10:22 AM
#6
Thread Starter
Member
THAT WAS THE PROBLEM!! THANK YOU VERY MUCH!! god i need to pay more attention in math classes...
XX The Signature of the Gods XX
-
Aug 9th, 2002, 05:32 PM
#7
Lively Member
guess what, it's one of my most done mistakes
but i'm glad i could help
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
|