Results 1 to 4 of 4

Thread: Simple trig gone drastically wrong

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2002
    Location
    Blue Mountains NSW Australia
    Posts
    160

    Unhappy Simple trig gone drastically wrong

    hi this program should draw a needle like line for a guage

    but i have got the lengths wrong for the needle when it is on different angles, can anyone make sense of where i have gone wrong?

    VB Code:
    1. Private Sub Timer1_Timer()
    2. Dim currenttemp, selectedtemp, a, b, c As Integer
    3. selectedtemp = selectedtemptext.Text
    4. currenttemp = Int(((selectedtemp + 15) - selectedtemp + 1) * Rnd + selectedtemp)
    5. 'read currenttemp
    6. Select Case currenttemp
    7. Case Is = selectedtemp: a = 0
    8. Case Is = (selectedtemp + 1): a = 12
    9. Case Is = (selectedtemp + 2): a = 24
    10. Case Is = (selectedtemp + 3): a = 36
    11. Case Is = (selectedtemp + 4): a = 48
    12. Case Is = (selectedtemp + 5): a = 60
    13. Case Is = (selectedtemp + 6): a = 72
    14. Case Is = (selectedtemp + 7): a = 84
    15. Case Is = (selectedtemp + 8): a = 96
    16. Case Is = (selectedtemp + 9): a = 108
    17. Case Is = (selectedtemp + 10): a = 120
    18. Case Is = (selectedtemp + 11): a = 132
    19. Case Is = (selectedtemp + 12): a = 144
    20. Case Is = (selectedtemp + 13): a = 156
    21. Case Is = (selectedtemp + 14): a = 168
    22. Case Is = (selectedtemp + 15): a = 180
    23. Case Is > (selectedtemp + 15): a = 180
    24. Case Is < selectedtemp: a = 0
    25. Case Else
    26. End Select
    27. '12,24,36,48,60,72,84,96,108,120,132,144,156,168,180
    28. 'a = currenttemp - selectedtemp
    29.  
    30. Cls
    31. If currenttemp < (selectedtemp + 1) Then
    32.     'set g to 0 if current temp is colder then selected temp
    33.     'and draw meter to 0
    34.     g = 0
    35.     Line1.X1 = 500
    36.     Line1.Y1 = 500
    37.     Line1.X2 = 140
    38.     Line1.Y2 = 500
    39.     Else
    40.     If a > 179 Then
    41.         'set g = 1 and draw meter at 180 because temp is too hot
    42.         g = 1
    43.         Line1.X1 = 500
    44.         Line1.Y1 = 500
    45.         Line1.X2 = 860
    46.         Line1.Y2 = 500
    47.         Else
    48.         If a > -1 And a < 91 Then
    49.             'draw meter if temp falls on left hand side
    50.             b = -(360 * (Sin((a) * 0.017453292)))
    51.             c = -(360 * (Cos((a) * 0.017453292)))
    52.             'Line (1000, 1000)-Step(c, b)
    53.             Line1.X1 = 500
    54.             Line1.Y1 = 500
    55.             Line1.X2 = c
    56.             Line1.Y2 = b
    57.             Else
    58.             If a > 90 And a < 181 Then
    59.                 'draw meter if temp falls on right hand side
    60.                 b = (360 * (Sin((a - 90) * 0.017453292)))
    61.                 c = -(360 * (Cos((a - 90) * 0.017453292)))
    62.                 'Line (1000, 1000)-Step(b, c)
    63.                 Line1.X1 = 500
    64.                 Line1.Y1 = 500
    65.                 Line1.X2 = (b + 500)
    66.                 Line1.Y2 = c
    67.             End If
    68.         End If
    69.     End If
    70. End If
    71. End Sub

    thanks for taking the time to even look at this.
    Last edited by Jack Daniels; Aug 1st, 2002 at 04:03 AM.
    Jack Daniels
    ICQ: 72074030
    VB 6.0

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