Q(uick)BASIC Function: SIN

Quick View

SIN

A math function that returns the sine of an angle given in radians

Worth knowing

Useful and cross-version information about the programming environments of QBasic and QuickBasic.

Syntax
  • ATN(numeric-expression)
  • COS(angle)
  • SIN(angle)
  • TAN(angle)
Description/Parameter(s)
numeric-expression The ratio between the sides of a right triangle.
angle An angle expressed in radians.

The ATN function returns an angle in radians.

To convert from degrees to radians, multiply degrees by (PI / 180).

Example
CONST PI=3.141592654 PRINT ATN(TAN(PI/4.0)), PI/4.0 'Output is: .7853981635 .7853981635 PRINT (COS(180 * (PI / 180))) 'Output is: -1 PRINT (SIN(90 * (PI / 180))) 'Output is: 1 PRINT (TAN(45 * (PI / 180))) 'Output is: 1.000000000205103
Syntax
  • SIN(numeric-expression)
Description/Parameter(s)

The SIN function is calculated with double-precision accuracy when x is a double-precision value. When x is not double precision, SIN is calculated with single-precision accuracy.

You can convert an angle measurement from degrees to radians by multiplying the degrees by π/180, where π = 3.141593.

To convert a radian value to degrees, multiply it by 57.2958.

Example

The example plots the graph of the polar equation r = 1 + sin n (θ). This figure is sometimes known as a cardioid, owing to its resemblance to a heart when n equals 1.

'***Programming example for the SIN function*** CLS CONST PI = 3.141593 SCREEN 1 : COLOR 1,1 'Medium resolution, blue background. WINDOW (-3,-2)-(3,2) 'Convert screen to Cartesian coordinates. INPUT "Number of petals = ", N CLS PSET (1,0) 'Set initial point. FOR Angle = 0 TO 2*PI STEP .02 R = 1 + SIN(N*Angle) 'Polar equation for "flower." X = R * COS(Angle) 'Convert polar coordinates to Y = R * SIN(Angle) 'Cartesian coordinates. LINE -(X,Y) 'Draw line from previous point to new point. NEXT END
Syntax
  • SIN(x)
Description/Parameter(s)
  • The argument x can be of any numeric type.

Usage Notes

  • The sine of an angle in a right triangle is the ratio between the length of the side opposite the angle and the length of the hypotenuse.
  • SIN is calculated in single precision if the argument x is an integer or single-precision value. If you use any other numeric data type, SIN is calculated in double-precision.
  • To convert values from degrees to radians, multiply the angle (in degrees) times PI/180 (or .0174532925199433) where PI = 3.141593.
  • To convert a radian value to degrees, multiply it by 180/PI (or 57.2957795130824) where PI = 3.141593.
Example

This example plots the graph of the polar equation r = 1 + sin(n * θ). This figure is sometimes known as a cardioid, owing to its resemblance to a heart when n equals 1.

CLS CONST PI = 3.141593 SCREEN 1: COLOR 1, 1 'Medium resolution, blue background. WINDOW (-3, -2)-(3, 2) 'Convert screen to Cartesian coordinates. INPUT "Number of petals = ", N CLS PSET (1, 0) 'Set initial point. FOR Angle = 0 TO 2 * PI STEP .02 R = 1 + SIN(N * Angle) 'Polar equation for "flower." X = R * COS(Angle) 'Convert polar coordinates to Y = R * SIN(Angle) 'Cartesian coordinates. LINE -(X, Y) 'Draw line from previous point to new point. NEXT END