|
-
May 21st, 2025, 10:04 AM
#1
[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?
Last edited by .paul.; May 21st, 2025 at 10:08 AM.
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 21st, 2025, 10:10 AM
#2
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.
-
May 21st, 2025, 10:15 AM
#3
Re: Calculating Trigonometrical formulas
cotangent = cosine/sine (instead of tangent which is sine/cosine)
All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
May 21st, 2025, 10:18 AM
#4
Re: Calculating Trigonometrical formulas
Thanks to both of you. I'll do some testing before i mark this resolved...
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 21st, 2025, 10:19 AM
#5
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|