Results 1 to 10 of 10

Thread: VB Trig Problem

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2001
    Location
    Hamilton, ON, Canada
    Posts
    43

    Exclamation

    i need to take the sin of an angel in degrees but VB does it in radians

    so, how do i get VB to calculate trig functions in degrees instead of radians?

  2. #2
    Banned
    Join Date
    Feb 2001
    Location
    Back to sh*tland
    Posts
    294
    Code:
    Pi= 3.141592654
    
    AngleR = AngleD * Pi / 180
    
    AngleD = AngleR * 180 / Pi

  3. #3

    Thread Starter
    Member
    Join Date
    Apr 2001
    Location
    Hamilton, ON, Canada
    Posts
    43
    i don't understand how i am supposed to use that code

    this is what i got:

    a is the angle in degrees
    s is the initian speed of the object
    dh is really dh/dt, the rate of change of the height of the object with respect to time

    a=45
    dh=sin(a)*s

    i need that dh (dh/dt) value for a formula,
    my problem is it calculates sin(45) as .850935 when sin(45) in degrees is .7071

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Convert the angle to radians THEN pass it to the trig functions. VB, like most things you'll encounter, uses radians because they are a much more practical type (they're based on REAL properties of a circle as opposed to the "hey, let's have 360 degrees in this thing" method)
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  5. #5
    Banned
    Join Date
    Feb 2001
    Location
    Back to sh*tland
    Posts
    294
    Code:
    AngleD is the angle in degrees and AngleR in Radians
    
    Type:
    dh=sin(a * Pi / 180) * s

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Code:
    Function Deg2Rad(dAngle As Double)
        Deg2Rad = dAngle * (Pi / 180)
    End Function
    ...
    Code:
    Debug.Print Sin(Deg2Rad(45))
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  7. #7
    Banned
    Join Date
    Feb 2001
    Location
    Back to sh*tland
    Posts
    294
    Originally posted by parksie
    Code:
    Function Deg2Rad(dAngle As Double)
        Deg2Rad = dAngle * (Pi / 180)
    End Function
    ...
    The parentisis aren't needed: Deg2Rad = dAngle * Pi / 180

    It doesn't really matter...

  8. #8
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Yeah, but I put them in because in my code I usually define the constant PIDIV180 to save VB having to recalculate it each time
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  9. #9
    Addicted Member Active's Avatar
    Join Date
    Jan 2001
    Location
    Lat: 13° 4' 46" N, Long: 80° 15' 20" E
    Posts
    209
    If you don't have a good memory of the value of pi
    like me use...

    Pi = 4*Atn(1)
    If you can't beat your computer at chess, try kickboxing !!!
    [Download Tag Editing Tools.]

  10. #10

    Thread Starter
    Member
    Join Date
    Apr 2001
    Location
    Hamilton, ON, Canada
    Posts
    43

    Smile Thanks For The Help

    thanks guys, that code did the trick

    my prog. works fine now

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