Subscribe:

Sunday, January 1, 2012

Home
Trigonometric Functions:
The Cosine of a Value






double cos(double x);
long double cosl(long double x);
The cos() function calculates the cosine of a number.
Consider AB the length of A to B, also referred to as the hypotenuse. Also consider AC the length of A to C which is the side adjacent to point A. The cosine of the angle at point A is the ratio AC/AB. That is, the ratio of the adjacent length, AC, over the length of the hypotenuse, AB:





The returned value, the ratio, is a double-precision number between –1 and 1.

Example: A form contains an Edit control named edtValue. After the user has typed a value and presses Enter, the OnKeyPress event retrieves the number typed in the edit box, calculates its cosine and displays it in the same Edit control:
//---------------------------------------------------
------------------------
void __fastcall TForm1::edtValueKeyPress(TObject *Sender, char &Key)
{
 if( Key == VK_RETURN )
 {
  double Value = edtValue->Text.ToDouble();
  double Cosinus = cos(Value);
  
  edtValue->Text = Cosinus;
 }
}
//---------------------------------------------------------------------------

Home
Trigonometric Functions:
The Sine of a Value






double sin(double x);
long double sinl(long double x);
The sin() function calculates the sine of a number.
Consider AB the length of A to B, also called the hypotenuse to point A. Also consider CB the length of C to B, which is the opposite side to point A. The sine represents the ratio of CB/AB; that is, the ratio of the opposite side, CB over the hypotenuse AB.
The sin() function takes a double-precision number and returns one between –1 and 1. The sinl() function is used for 10-byte values.
Example: A form contains an Edit control named edtValue. After the user has typed a value and presses Enter, the OnKeyPress event retrieves the number typed in the edit box, calculates its sine and displays the result in the same Edit control:
//---------------------------------------------------------------------------
void __fastcall TForm1::edtValueKeyPress(TObject *Sender, char &Key)
{
 if( Key == VK_RETURN )
 {
  double Value = edtValue->Text.ToDouble();
  double Sinus = sin(Value);
  
  edtValue->Text = Sinus;
 }
}
//---------------------------------------------------------------------------








  
Home
Trigonometric Functions: Tangents

 



 
The C/C++ tan Functions

double tan(double x);
long double tanl(long double x);
The tan() function calculates the tangent of a number.

In geometry, consider AC the length of A to C. Also consider BC the length of B to C. The tangent is the result of BC/AC; that is, the ratio of BC over AC.
Example: A form contains an Edit control named edtValue. After the user has typed a value and presses Enter, the OnKeyPress event retrieves the number typed in the edit box, calculates its tangent and displays the result in the same Edit control:
//---------------------------------------------------------------------------
void __fastcall TForm1::edtValueKeyPress(TObject *Sender, char &Key)
{
 if( Key == VK_RETURN )
 {
  double Value = edtValue->Text.ToDouble();
  double Tangent = tan(Value);
  
  edtValue->Text = Tangent;
 }
}
//---------------------------------------------------------------------------

0 comments:

Post a Comment