logo VB.Net - Trignometry
Guide Contents
DigitalDan Home Page

Degrees and Radians
VB.Net has built in functions for normal trignometry, (Sin, Cos, Tan etc.) however, they are subtly different to the equivelent functions on a typical calculator. The computer functions work use an anghle measurement called radians but your calcultaor will probably use degrees. Just like the length units of feet and metres, using the wrong unit can cause unexpected results.
 
The following functions will convert degrees to radians or radians to degrees. (Math.PI is just a number = 3.14159265389793...)
 
Private Shared Function Degrees_To_Radians(deg As Double) As Double
Return deg * 180 / Math.PI
End Function
'
'
Private Shared Function Radians_To_Degrees(rad As Double) As Double
Return rad * Math.PI / 180
End Function

 
Sine, Cosine and Tangent
The VB.NET versions of Sin, Cos, Tan etc. reside in the Math namespace. This means that we must either use the imports statement
Imports System.Math
at the start of our program (immediately after the Option startements or if you do not use Option it is before Public Class line.) Alternatively, you could prefix every reference to a built-in trig function with "Math."
This example calculate Sin(angle) for an angle in degrees. Notice the convertion from degrees to radians and the Math. prefix added the Sin function (Cos and Tan examples given in code block at end of this page)
 
Private Function Sin_Degrees(angle As Double) As Double
Dim radians As Double = angle * 180 / Math.PI
Return Math.Sin(radians)
End Function

 
Inv-Sine, Inv-Cosine and Inv-Tangent
Now we will look at the Inverse Trig functions. To find the inverse (reverse of) Sin(angle) on most calculators you enter INV Sin
When using VB you prefix the function name (Sin) with the letter A (ASin) instead of using INV
VB will return the result in radians, so we will usually need to convert radians back to degrees. (INV-Cos and INV-Tan examples given in code block at end of this page)
 
Private Shared Function Inv_Sin_Degrees(valu As Double) As Double
Dim radians As Double = Asin(valu)
Return radians * Math.PI / 180
End Function

 
Hyp and Inv-Hyp versions of Sin, Cos and Tan
Your calcaulator may also have a HYP key, this is used for special Hyperbolic variants of the basic Sin, Cos, Tan functions.
VB.Net has built in Hyperbolic and Inverse Hyperbolic functions in the Math namespace and we will again use Imports or the Math. prefix
We indicate that the HYP version is required by adding a h to the end of the function name (Math.Sinh)
As before, we can indicate INV by prefixing the function with the letter A. (Math.ASinh)
 
Examples of common Normal, INV, HYP and INV-HYP Functions
 
Private Shared Function Sin_Degrees(angle As Double) As Double
Dim radians As Double = angle * 180 / Math.PI
Return Math.Sin(radians)
End Function
'
Private Shared Function Inv_Sin_Degrees(valu As Double) As Double
Dim radians As Double = Asin(valu)
Return radians * Math.PI / 180
End Function
'
Private Shared Function Cos_Degrees(angle As Double) As Double
Dim radians As Double = angle * 180 / Math.PI
Return Math.Cos(radians)
End Function
'
Private Shared Function Inv_Cos_Degrees(valu As Double) As Double
Dim radians As Double = Acos(valu)
Return radians * Math.PI / 180
End Function
'
Private Shared Function Tan_Degrees(angle As Double) As Double
Dim radians As Double = angle * 180 / Math.PI
Return Math.Tan(radians)
End Function
'
Private Shared Function Inv_Tan_Degrees(valu As Double) As Double
Dim radians As Double = Atan(valu)
Return radians * Math.PI / 180
End Function
'
Private Shared Function Hyp_Sin_Degrees(angle As Double) As Double
Dim radians As Double = angle * 180 / Math.PI
Return Math.Sinh(radians)
End Function
'
Private Shared Function Inv_Hyp_Sin_Degrees(valu As Double) As Double
Dim radians As Double = Asinh(valu)
Return radians * Math.PI / 180
End Function
'
Private Shared Function Hyp_Cos_Degrees(angle As Double) As Double
Dim radians As Double = angle * 180 / Math.PI
Return Math.Cosh(radians)
End Function
'
Private Shared Function Inv_Hyp_Cos_Degrees(valu As Double) As Double
Dim radians As Double = Acosh(valu)
Return radians * Math.PI / 180
End Function
'
Private Shared Function Hyp_Tan_Degrees(angle As Double) As Double
Dim radians As Double = angle * 180 / Math.PI
Return Math.Tanh(radians)
End Function
'
Private Shared Function Inv_Hyp_Tan_Degrees(valu As Double) As Double
Dim radians As Double = Atanh(valu)
Return radians * Math.PI / 180
End Function

DigitalDan.co.uk ... Hits = 293