Results 1 to 16 of 16

Thread: [RESOLVED] Trigonometry… Not getting right results...

Threaded View

  1. #1

    Thread Starter
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Resolved [RESOLVED] Trigonometry… Not getting right results...

    I have this chart i'm testing my results against.
    Are these even correct values? Any pointers where i'm going wrong?

    Name:  487880178_1352309669203972_7403051815264587941_n.jpg
Views: 422
Size:  57.6 KB

    Code:
    Private Sub calculate()
        Select Case ComboBox1.SelectedIndex
            Case 0 ' sine(sin)
                Label3.Text = $"Math.Sin({NumericUpDown1.Value} * Math.PI / 180)"
                Label4.Text = round(sine(toRadians(NumericUpDown1.Value)))
            Case 1 ' cosine(cos)
                Label3.Text = $"Math.Cos({NumericUpDown1.Value} * Math.PI / 180)"
                Label4.Text = round(cosine(toRadians(NumericUpDown1.Value)))
            Case 2 ' tangent(tan)
                Label3.Text = $"Math.Tan({NumericUpDown1.Value} * Math.PI / 180)"
                Label4.Text = round(tangent(toRadians(NumericUpDown1.Value)))
            Case 3 ' cotangent(cot)
                Label3.Text = $"1 / Math.Tan({NumericUpDown1.Value} * Math.PI / 180)"
                Label4.Text = round(cotangent(toRadians(NumericUpDown1.Value)))
            Case 4 ' secant(sec)
                Label3.Text = $"1 / Math.Cos({NumericUpDown1.Value} * Math.PI / 180)"
                Label4.Text = round(secant(toRadians(NumericUpDown1.Value)))
            Case 5 ' cosecant(csc)
                Label3.Text = $"1 / Math.Sin({NumericUpDown1.Value} * Math.PI / 180)"
                Label4.Text = round(cosecant(toRadians(NumericUpDown1.Value)))
            Case Else ' -1
                Label3.Text = ""
                Label4.Text = ""
        End Select
    End Sub
    
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        NumericUpDown1.Maximum = Decimal.MaxValue
        NumericUpDown2.Maximum = Integer.MaxValue
    End Sub
    
    Private Function sine(radians As Double) As Double
        Return Math.Sin(radians)
    End Function
    
    Private Function cosine(radians As Double) As Double
        Return Math.Cos(radians)
    End Function
    
    Private Function tangent(radians As Double) As Double
        Return Math.Tan(radians)
    End Function
    
    Private Function cotangent(radians As Double) As Double
        Dim t As Double = tangent(radians)
        Return 1 / t
    End Function
    
    Private Function secant(radians As Double) As Double
        Dim c As Double = cosine(radians)
        Return 1 / c
    End Function
    
    Private Function cosecant(radians As Double) As Double
        Dim s As Double = sine(radians)
        Return 1 / s
    End Function
    
    Private Function toRadians(d As Decimal) As Double
        Return d * Math.PI / 180
    End Function
    
    Private Function round(d As Double) As String
        If Double.IsNegativeInfinity(d) Or Double.IsPositiveInfinity(d) Then Return "Infinity"
        Return d.ToString
    End Function
    Last edited by .paul.; May 27th, 2025 at 05:05 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width