Results 1 to 10 of 10

Thread: Angles for a line

  1. #1

    Thread Starter
    Addicted Member hypnos's Avatar
    Join Date
    Aug 2000
    Location
    UK
    Posts
    183

    Talking Angles for a line

    Yo all,
    Here's what I'm wanting to do... I have a form with a picture box, text box and a button. I wanted to be able to enter a degree into the text box and then press the button, which would draw a line in the picture box facing that degree. Unfortunately, it didn't quite turn out that way. My lack of knowledge led me to creating a really lame piece of code that should be on a stand-up comedians jokes list. Now, I'm gonna' show you my code but please...before you start rolling over on the floor in hysterics...remember, I'm an idiot

    Code:
    Const PI As Single = 3.14159
    
    Private Function DtoR(degrees As Double) As Double
        Dim rad As Double
        rad = degrees / PI
        DtoR = rad * 180
    End Function
    
    
    Private Sub cmdGo_Click()
        Dim degrees As Double
        Dim x2 As Double
        Dim y2 As Double
        
        
        face.Cls
        degrees = Val(txtDegrees.Text)
        x2 = Sin(DtoR(degrees))
        y2 = -(Cos(DtoR(degrees)))
        
        face.Line (face.Width / 2, face.Height / 2)-(x2 * 700, y2 * 700)
        
        
    End Sub
    If somebody could please have a look and correct it for me (after you've stopped laughing) I would be very grateful

  2. #2
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Not too sure, but I think your problem lies in your DtoR function. I believe it should be:

    DtoR = degrees / (180 / pi)

    Once again, not too sure.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  3. #3

    Thread Starter
    Addicted Member hypnos's Avatar
    Join Date
    Aug 2000
    Location
    UK
    Posts
    183

    Post

    Thanks for trying Sastraxi, but unfortunately, that's not it

  4. #4
    Member
    Join Date
    Jul 2001
    Location
    Minneapolis, MN USA
    Posts
    32
    I'm thinking it might have to do with your last couple parameters on the .Line method ...

    Remember that the way you're calc'ing x2 & y2 makes them relative to your origin. And since your origin isn't the upper-left corner (0,0), then you need to do a bit more calc'ing ...

    Code:
    OriginX = face.Width \ 2
    OriginY = face.Height \ 2
    
    face.Line (OriginX, OriginY) - (OriginX + (x2 * 700), OriginY + (y2 * 700))
    ... or something like that. As an aside, notice that I used integer divide ("\") instead of the standard divide ("/") because it's faster and it results in an integer, which you'll need for your pixel coordinates anyway.

    Hope that helps.

    -Bryk

  5. #5

    Thread Starter
    Addicted Member hypnos's Avatar
    Join Date
    Aug 2000
    Location
    UK
    Posts
    183
    I did that Brykovian and the results did change! Unfortunately it's still not working as it should. After making the change you suggested I only needed to go through numbers 1 to 10 for the line to do a complete revolution. It is a start but still, more to do Any more suggestions anybody?

  6. #6
    Zaei
    Guest
    Code:
    x2 = Cos(DtoR(degrees))
    y2 = Sin(DtoR(degrees))
    Z.

  7. #7

    Thread Starter
    Addicted Member hypnos's Avatar
    Join Date
    Aug 2000
    Location
    UK
    Posts
    183
    Thanks for trying but that makes it worse

  8. #8
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Code:
    Private Sub cmdGo_Click()
        Dim rad As Double
        face.Cls
        rad = Val(txtDegrees.Text) * 1.74532925199433E-02 'pi/180
        face.Line (face.Width / 2, face.Height / 2)-Step(Cos(rad) * 700, Sin(rad) * 700)
    End Sub
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  9. #9
    Member
    Join Date
    Jul 2001
    Location
    Minneapolis, MN USA
    Posts
    32
    Yah, hypnos ... I think Kedaman's code should do it ...

    You did have your DtoR function wrong though ... you had the 180 and Pi thing flip-flopped ... shoulda been:
    Code:
    Private Function DtoR(degrees As Double) As Double
        Dim rad As Double
        rad = degrees / 180
        DtoR = rad * PI
    End Function
    Ked's code takes this into effect, plus puts all of the intermediate steps onto fewer lines.

    -Bryk

    p.s. I'd forgot about the "step" feature on the .Line method ...

  10. #10

    Thread Starter
    Addicted Member hypnos's Avatar
    Join Date
    Aug 2000
    Location
    UK
    Posts
    183
    I'd like to thank all you guys for the help. You was right Brykovian, it was my Degrees to Radians function that was wrong. So, I changed it to the code you mentioned:

    Code:
    Private Function DtoR(degrees As Double) As Double
        Dim rad As Double
        rad = degrees / 180
        DtoR = rad * PI
    End Function
    Now it's working perfectly! Once again, thank you all for the 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