當前位置: 首頁>>代碼示例>>VB.NET>>正文


VB.NET Math.Cos方法代碼示例

本文整理匯總了VB.NET中System.Math.Cos方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET Math.Cos方法的具體用法?VB.NET Math.Cos怎麽用?VB.NET Math.Cos使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Math的用法示例。


在下文中一共展示了Math.Cos方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。

示例1: SinCos

' Example for the trigonometric Math.Sin( Double ) and Math.Cos( Double ) methods.
Module SinCos
   
    Sub Main()
        Console.WriteLine( _
            "This example of trigonometric " & _
            "Math.Sin( double ) and Math.Cos( double )" & vbCrLf & _
            "generates the following output." & vbCrLf)
        Console.WriteLine( _
            "Convert selected values for X to radians " & vbCrLf & _
            "and evaluate these trigonometric identities:")
        Console.WriteLine( _
            "   sin^2(X) + cos^2(X) = 1" & vbCrLf & _ 
            "   sin(2 * X) = 2 * sin(X) * cos(X)")
        Console.WriteLine("   cos(2 * X) = cos^2(X) - sin^2(X)")
          
        UseSineCosine(15.0)
        UseSineCosine(30.0)
        UseSineCosine(45.0)
          
        Console.WriteLine( _
            vbCrLf & "Convert selected values for X and Y to radians" & _ 
            vbCrLf & "and evaluate these trigonometric identities:")
        Console.WriteLine("   sin(X + Y) = sin(X) * cos(Y) + cos(X) * sin(Y)")
        Console.WriteLine("   cos(X + Y) = cos(X) * cos(Y) - sin(X) * sin(Y)")
          
        UseTwoAngles(15.0, 30.0)
        UseTwoAngles(30.0, 45.0)
    End Sub
      
    ' Evaluate trigonometric identities with a given angle.
    Sub UseSineCosine(degrees As Double)

        Dim angle As Double = Math.PI * degrees / 180.0
        Dim sinAngle As Double = Math.Sin(angle)
        Dim cosAngle As Double = Math.Cos(angle)
          
        ' Evaluate sin^2(X) + cos^2(X) = 1.
        Console.WriteLine( _
            vbCrLf & "                           Math.Sin({0} deg) = {1:E16}" & _ 
            vbCrLf & "                           Math.Cos({0} deg) = {2:E16}", _
            degrees, Math.Sin(angle), Math.Cos(angle))
        Console.WriteLine( _
            "(Math.Sin({0} deg))^2 + (Math.Cos({0} deg))^2 = {1:E16}", _ 
            degrees, sinAngle * sinAngle + cosAngle * cosAngle)
          
        ' Evaluate sin(2 * X) = 2 * sin(X) * cos(X).
        Console.WriteLine( _
            "                           Math.Sin({0} deg) = {1:E16}", _ 
            2.0 * degrees, Math.Sin(2.0 * angle))
        Console.WriteLine( _
            "    2 * Math.Sin({0} deg) * Math.Cos({0} deg) = {1:E16}", _ 
            degrees, 2.0 * sinAngle * cosAngle)
          
        ' Evaluate cos(2 * X) = cos^2(X) - sin^2(X).
        Console.WriteLine( _
            "                           Math.Cos({0} deg) = {1:E16}", _ 
            2.0 * degrees, Math.Cos(2.0 * angle))
        Console.WriteLine( _
            "(Math.Cos({0} deg))^2 - (Math.Sin({0} deg))^2 = {1:E16}", _ 
            degrees, cosAngle * cosAngle - sinAngle * sinAngle)

    End Sub
       
    ' Evaluate trigonometric identities that are functions of two angles.
    Sub UseTwoAngles(degreesX As Double, degreesY As Double)

        Dim angleX As Double = Math.PI * degreesX / 180.0
        Dim angleY As Double = Math.PI * degreesY / 180.0
          
        ' Evaluate sin(X + Y) = sin(X) * cos(Y) + cos(X) * sin(Y).
        Console.WriteLine( _
            vbCrLf & "        Math.Sin({0} deg) * Math.Cos({1} deg) +" & _ 
            vbCrLf & "        Math.Cos({0} deg) * Math.Sin({1} deg) = {2:E16}", _
            degreesX, degreesY, Math.Sin(angleX) * Math.Cos(angleY) + _
            Math.Cos(angleX) * Math.Sin(angleY))
        Console.WriteLine( _
            "                           Math.Sin({0} deg) = {1:E16}", _
            degreesX + degreesY, Math.Sin(angleX + angleY))
          
        ' Evaluate cos(X + Y) = cos(X) * cos(Y) - sin(X) * sin(Y).
        Console.WriteLine( _
            "        Math.Cos({0} deg) * Math.Cos({1} deg) -" & vbCrLf & _ 
            "        Math.Sin({0} deg) * Math.Sin({1} deg) = {2:E16}", _
            degreesX, degreesY, Math.Cos(angleX) * Math.Cos(angleY) - _
            Math.Sin(angleX) * Math.Sin(angleY))
        Console.WriteLine( _
            "                           Math.Cos({0} deg) = {1:E16}", _
            degreesX + degreesY, Math.Cos(angleX + angleY))

    End Sub
End Module 'SinCos

' This example of trigonometric Math.Sin( double ) and Math.Cos( double )
開發者ID:VB.NET開發者,項目名稱:System,代碼行數:94,代碼來源:Math.Cos

輸出:

Convert selected values for X to radians
and evaluate these trigonometric identities:
sin^2(X) + cos^2(X) = 1
sin(2 * X) = 2 * sin(X) * cos(X)
cos(2 * X) = cos^2(X) - sin^2(X)

Math.Sin(15 deg) = 2.5881904510252074E-001
Math.Cos(15 deg) = 9.6592582628906831E-001
(Math.Sin(15 deg))^2 + (Math.Cos(15 deg))^2 = 1.0000000000000000E+000
Math.Sin(30 deg) = 4.9999999999999994E-001
2 * Math.Sin(15 deg) * Math.Cos(15 deg) = 4.9999999999999994E-001
Math.Cos(30 deg) = 8.6602540378443871E-001
(Math.Cos(15 deg))^2 - (Math.Sin(15 deg))^2 = 8.6602540378443871E-001

Math.Sin(30 deg) = 4.9999999999999994E-001
Math.Cos(30 deg) = 8.6602540378443871E-001
(Math.Sin(30 deg))^2 + (Math.Cos(30 deg))^2 = 1.0000000000000000E+000
Math.Sin(60 deg) = 8.6602540378443860E-001
2 * Math.Sin(30 deg) * Math.Cos(30 deg) = 8.6602540378443860E-001
Math.Cos(60 deg) = 5.0000000000000011E-001
(Math.Cos(30 deg))^2 - (Math.Sin(30 deg))^2 = 5.0000000000000022E-001

Math.Sin(45 deg) = 7.0710678118654746E-001
Math.Cos(45 deg) = 7.0710678118654757E-001
(Math.Sin(45 deg))^2 + (Math.Cos(45 deg))^2 = 1.0000000000000000E+000
Math.Sin(90 deg) = 1.0000000000000000E+000
2 * Math.Sin(45 deg) * Math.Cos(45 deg) = 1.0000000000000000E+000
Math.Cos(90 deg) = 6.1230317691118863E-017
(Math.Cos(45 deg))^2 - (Math.Sin(45 deg))^2 = 2.2204460492503131E-016

Convert selected values for X and Y to radians
and evaluate these trigonometric identities:
sin(X + Y) = sin(X) * cos(Y) + cos(X) * sin(Y)
cos(X + Y) = cos(X) * cos(Y) - sin(X) * sin(Y)

Math.Sin(15 deg) * Math.Cos(30 deg) +
Math.Cos(15 deg) * Math.Sin(30 deg) = 7.0710678118654746E-001
Math.Sin(45 deg) = 7.0710678118654746E-001
Math.Cos(15 deg) * Math.Cos(30 deg) -
Math.Sin(15 deg) * Math.Sin(30 deg) = 7.0710678118654757E-001
Math.Cos(45 deg) = 7.0710678118654757E-001

Math.Sin(30 deg) * Math.Cos(45 deg) +
Math.Cos(30 deg) * Math.Sin(45 deg) = 9.6592582628906831E-001
Math.Sin(75 deg) = 9.6592582628906820E-001
Math.Cos(30 deg) * Math.Cos(45 deg) -
Math.Sin(30 deg) * Math.Sin(45 deg) = 2.5881904510252085E-001
Math.Cos(75 deg) = 2.5881904510252096E-001

示例2: Tester

Public Class Tester
    Public Shared Sub Main
        Dim X As Single
        Dim Y As Single

        X = CSng( Math.Cos(100))
        Y = CSng( Math.Sin(100))

        Console.WriteLine(X)
        Console.WriteLine(Y)
        
    End Sub

End Class
開發者ID:VB程序員,項目名稱:System,代碼行數:14,代碼來源:Math.Cos


注:本文中的System.Math.Cos方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。