Results 1 to 7 of 7

Thread: angles in vb6

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2002
    Location
    I'll kick yo' @$$!!
    Posts
    44

    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

  2. #2
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    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.

  3. #3

    Thread Starter
    Member
    Join Date
    Apr 2002
    Location
    I'll kick yo' @$$!!
    Posts
    44
    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:
    1. Option Explicit
    2.   Dim angle, pi As Integer
    3.  
    4. Private Sub form_load()
    5.   pi = 3.14159
    6. End Sub
    7.  
    8. Private Sub tmr1_Timer()
    9.   'pic1.Cls
    10.   If angle <= 359 Then
    11.     pic1.Line (278.5, 186.5)-(278.5 + 100 * Math.Sin(angle * (pi / 180)), 186.5 + 100 * Math.Cos(angle * (pi / 180))), vbBlack
    12.     angle = angle + 1
    13.   End If
    14.   'If angle >= 360 Then angle = 0
    15.   lbl1.Caption = "Angle = " & angle
    16. 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

  4. #4
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    You need to draw a line between the start and end points of your arc to get a full circle.

    Z.

  5. #5
    Lively Member
    Join Date
    Aug 2002
    Location
    SwitzerLANd
    Posts
    65
    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=-

  6. #6

    Thread Starter
    Member
    Join Date
    Apr 2002
    Location
    I'll kick yo' @$$!!
    Posts
    44
    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

  7. #7
    Lively Member
    Join Date
    Aug 2002
    Location
    SwitzerLANd
    Posts
    65
    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
  •  



Click Here to Expand Forum to Full Width