[RESOLVED] Calculating Trigonometrical formulas
This is a small calculator i'm writing. I just need help with VB.Net formulas for cotangent, secant, and cosecant.
Given an angle (NumericUpDown1.Value), how would i complete this code?
Code:
Private Sub calculate()
Select Case ComboBox1.SelectedIndex
Case 0 ' sine(sin)
Label3.Text = $"Math.Sin({NumericUpDown1.Value})"
Label4.Text = Math.Sin(NumericUpDown1.Value).ToString
Case 1 ' cosine(cos)
Label3.Text = $"Math.Cos({NumericUpDown1.Value})"
Label4.Text = Math.Cos(NumericUpDown1.Value).ToString
Case 2 ' tangent(tan)
Label3.Text = $"Math.Tan({NumericUpDown1.Value})"
Label4.Text = Math.Tan(NumericUpDown1.Value).ToString
Case 3 ' cotangent(cot)
Label3.Text = $"1 / Math.Tan({NumericUpDown1.Value})"
Label4.Text = 1 / Math.Tan(NumericUpDown1.Value).ToString '???
Case 4 ' secant(sec)
Label3.Text = ""
Label4.Text = "" '???
Case 5 ' cosecant(csc)
Label3.Text = ""
Label4.Text = "" '???
Case Else ' -1
Label3.Text = ""
Label4.Text = ""
End Select
End Sub
I'm just testing this now. Should the angle be given in Radians?
Re: Calculating Trigonometrical formulas
Secant = 1/Cosine
Cosecant = 1/Sin
Of course, because both Sin and Cosine can equal 0 for theta=2n*pi and theta=2*(n+1)*pi, respectively, and where n is any integer, you need to code around "1/0" situations.
Re: Calculating Trigonometrical formulas
cotangent = cosine/sine (instead of tangent which is sine/cosine)
Re: Calculating Trigonometrical formulas
Thanks to both of you. I'll do some testing before i mark this resolved...
Re: Calculating Trigonometrical formulas
And for working with angles in degrees instead of radians:
Code:
Dim angleRadians As Double = angleDegrees * Math.PI / 180
Dim sinValue As Double = Math.Sin(angleRadians)
Dim cosValue As Double = Math.Cos(angleRadians)
Dim tanValue As Double = Math.Tan(angleRadians)
Dim cot As Double = 1 / tanValue
Dim sec As Double = 1 / cosValue
Dim csc As Double = 1 / sinValue