Machsupport Forum

Mach Discussion => VB and the development of wizards => Topic started by: Tarak on September 06, 2007, 05:41:07 PM

Title: Trouble with a trigonometry calculation in VB?
Post by: Tarak 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.
Title: Re: Trouble with a trigonometry calculation in VB?
Post by: poppabear 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
Title: Re: Trouble with a trigonometry calculation in VB?
Post by: Tarak 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
Title: Re: Trouble with a trigonometry calculation in VB?
Post by: Tarak 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?