Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Math.Sin Method

Returns the sine of the specified angle.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)
[SecuritySafeCriticalAttribute]
public static double Sin(
	double a
)

Parameters

a
Type: System.Double
An angle, measured in radians.

Return Value

Type: System.Double
The sine of a. If a is equal to NaN, NegativeInfinity, or PositiveInfinity, this method returns NaN.

The angle, a, must be in radians. Multiply by Math.PI/180 to convert degrees to radians.

Acceptable values of d range from approximately -9223372036854775295 to approximately 9223372036854775295. For values outside of this range, the Sin method returns d unchanged rather than throwing an exception.

Platform Notes

Silverlight for Windows Phone Silverlight for Windows Phone

 The value of Math.Sin(Math.PI/2) is 0.99999999999999989. The value on Windows is 1.

The following example uses Sin to evaluate certain trigonometric identities for selected angles.


// Example for the trigonometric Math.Sin( double ) 
// and Math.Cos( double ) methods.
using System;

class Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      outputBlock.Text +=
          "This example of trigonometric " +
          "Math.Sin( double ) and Math.Cos( double )\n" +
          "generates the following output.\n" + "\n";
      outputBlock.Text +=
          "Convert selected values for X to radians \n" +
          "and evaluate these trigonometric identities:" + "\n";
      outputBlock.Text += "   sin^2(X) + cos^2(X) == 1\n" +
                         "   sin(2 * X) == 2 * sin(X) * cos(X)" + "\n";
      outputBlock.Text += "   cos(2 * X) == cos^2(X) - sin^2(X)" + "\n";

      UseSineCosine(outputBlock, 15.0);
      UseSineCosine(outputBlock, 30.0);
      UseSineCosine(outputBlock, 45.0);

      outputBlock.Text +=
          "\nConvert selected values for X and Y to radians \n" +
          "and evaluate these trigonometric identities:" + "\n";
      outputBlock.Text += "   sin(X + Y) == sin(X) * cos(Y) + cos(X) * sin(Y)" + "\n";
      outputBlock.Text += "   cos(X + Y) == cos(X) * cos(Y) - sin(X) * sin(Y)" + "\n";

      UseTwoAngles(outputBlock, 15.0, 30.0);
      UseTwoAngles(outputBlock, 30.0, 45.0);
   }

   // Evaluate trigonometric identities with a given angle.
   static void UseSineCosine(System.Windows.Controls.TextBlock outputBlock, double degrees)
   {
      double angle = Math.PI * degrees / 180.0;
      double sinAngle = Math.Sin(angle);
      double cosAngle = Math.Cos(angle);

      // Evaluate sin^2(X) + cos^2(X) == 1.
      outputBlock.Text += String.Format(
          "\n                           Math.Sin({0} deg) == {1:E16}\n" +
          "                           Math.Cos({0} deg) == {2:E16}",
          degrees, Math.Sin(angle), Math.Cos(angle)) + "\n";
      outputBlock.Text += String.Format(
          "(Math.Sin({0} deg))^2 + (Math.Cos({0} deg))^2 == {1:E16}",
          degrees, sinAngle * sinAngle + cosAngle * cosAngle) + "\n";

      // Evaluate sin(2 * X) == 2 * sin(X) * cos(X).
      outputBlock.Text += String.Format(
          "                           Math.Sin({0} deg) == {1:E16}",
          2.0 * degrees, Math.Sin(2.0 * angle)) + "\n";
      outputBlock.Text += String.Format(
          "    2 * Math.Sin({0} deg) * Math.Cos({0} deg) == {1:E16}",
          degrees, 2.0 * sinAngle * cosAngle) + "\n";

      // Evaluate cos(2 * X) == cos^2(X) - sin^2(X).
      outputBlock.Text += String.Format(
          "                           Math.Cos({0} deg) == {1:E16}",
          2.0 * degrees, Math.Cos(2.0 * angle)) + "\n";
      outputBlock.Text += String.Format(
          "(Math.Cos({0} deg))^2 - (Math.Sin({0} deg))^2 == {1:E16}",
          degrees, cosAngle * cosAngle - sinAngle * sinAngle) + "\n";
   }

   // Evaluate trigonometric identities that are functions of two angles.
   static void UseTwoAngles(System.Windows.Controls.TextBlock outputBlock, double degreesX, double degreesY)
   {
      double angleX = Math.PI * degreesX / 180.0;
      double angleY = Math.PI * degreesY / 180.0;

      // Evaluate sin(X + Y) == sin(X) * cos(Y) + cos(X) * sin(Y).
      outputBlock.Text += String.Format(
          "\n        Math.Sin({0} deg) * Math.Cos({1} deg) +\n" +
          "        Math.Cos({0} deg) * Math.Sin({1} deg) == {2:E16}",
          degreesX, degreesY, Math.Sin(angleX) * Math.Cos(angleY) +
          Math.Cos(angleX) * Math.Sin(angleY)) + "\n";
      outputBlock.Text += String.Format(
          "                           Math.Sin({0} deg) == {1:E16}",
          degreesX + degreesY, Math.Sin(angleX + angleY)) + "\n";

      // Evaluate cos(X + Y) == cos(X) * cos(Y) - sin(X) * sin(Y).
      outputBlock.Text += String.Format(
          "        Math.Cos({0} deg) * Math.Cos({1} deg) -\n" +
          "        Math.Sin({0} deg) * Math.Sin({1} deg) == {2:E16}",
          degreesX, degreesY, Math.Cos(angleX) * Math.Cos(angleY) -
          Math.Sin(angleX) * Math.Sin(angleY)) + "\n";
      outputBlock.Text += String.Format(
          "                           Math.Cos({0} deg) == {1:E16}",
          degreesX + degreesY, Math.Cos(angleX + angleY)) + "\n";
   }
}

/*
This example of trigonometric Math.Sin( double ) and Math.Cos( double )
generates the following output.

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
*/


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.