Hello Guest it is April 26, 2024, 11:01:55 PM

Author Topic: Trouble with a trigonometry calculation in VB?  (Read 3917 times)

0 Members and 1 Guest are viewing this topic.

Offline Tarak

*
  •  229 229
    • View Profile
Trouble with a trigonometry calculation in VB?
« on: September 06, 2007, 05:41:07 PM »
Hi guys I'm attempting to make a small calculator to go on one of the pages, I tried to make this myself, but it doesn't quite work properly......it's so close, it just doesn't calculate correctly, I think it's got to do with how it calculates as Radians not degrees:

Lead=PI*Ø/Tan of Angle

Here's what I have so far.

Angle=GetUserDRO(1201)'read angle
Ø=GetUserDRO(1202)'read Ø
SetOEMDRO (1203,0)'Set DRO 1203 to 0
Radians=Tan(Angle)
Degrees=(Radians*180)/3.141592654

If GetUserDRO(1201) Then
   If GetUserDRO(1202) Then
   Message "O.K Parameter"
   SetOEMDRO (1203,3.141592654*Ø/Tan(Degrees))'Set DRO 1203 to Answer
   Else
   Message "Invalid Parameter"
   End If   
Else
Message "Invalid Parameter"
End If

Thanks guys.
« Last Edit: September 06, 2007, 08:29:49 PM by Darc »

Offline poppabear

*
  • *
  •  2,235 2,235
  • Briceville, TN, USA
    • View Profile
Re: Trouble with a trigonometry calculation in VB?
« Reply #1 on: September 06, 2007, 10:43:55 PM »
Try these values:
pi = 4 * Atn(1)

slope stuff:
a=y2-y1
b=x2-x1
ang=(180/pi) * Atn(a/b)

not really sure what your looking to do...........

scott
fun times

Offline Tarak

*
  •  229 229
    • View Profile
Re: Trouble with a trigonometry calculation in VB?
« Reply #2 on: September 13, 2007, 07:54:49 AM »
Hi Scott, Thanks for the reply, I didn't quite know how to use what you suggested.
Here's a better example of what I am after.
e.g I need to calculate the lead of a spring (or pitch for single start), all I have is the Ø and the angle of the helix.
Here's the equation I have, but it still isn't quite working, I think it's because of VB using Radians, not degrees (not sur though it's just what I've read)
I feel it's so close......


'Lead=PI*Ø/Tan of Angle

Helix=GetUserDRO(1201)'read helix angle
Ø=GetUserDRO(1202)'read Ø
SetOEMDRO (1203,0)'Set DRO 1203 to 0
Radians=Tan(Helix)
Degrees=(Radians*180)/3.141592654

If GetUserDRO(1201) Then
   If GetUserDRO(1202) Then
   SetOEMDRO (1203,3.141592654*Ø/Tan(Degrees)) 'Set DRO 1203 to Answer
   Else
   Message "Invalid Parameter"
   End If   
Else
Message "Invalid Parameter"
End If

Offline Tarak

*
  •  229 229
    • View Profile
Re: Trouble with a trigonometry calculation in VB?
« Reply #3 on: September 13, 2007, 05:38:14 PM »
Ah HA............. Beautiful, I got it to work, I didn't realise the input degrees needed to be in Radians, Thanks guys.

Is it possible to display the answer to a the calculation in a User label, or can you only use dro's?

Similar to this:
'SetUserLabel 6, "Last calculated lead was _ _ _"

Make sense?
« Last Edit: September 13, 2007, 05:43:35 PM by Darc »