9.7 Trigonometric functions

Whenever angles are included in your calculations or you perform coordinate transformations, you can use a variety of trigonometric functions in Gambas.

FunctionDescription
Rad(Angle AS Float) AS FloatConverts the degree measure of an angle to radian measure.
Deg(Angle AS Float) AS FloatConverts the radians of an angle into degrees.
Pi([ Number AS Float]Multiplies π with the value of Number and returns the product. If the optional argument Number is not set, the default value Number=1 is set.
Sin(Angle AS Float)Calculates the sine of an angle. The angle must be specified in radian measure! The function value is within the interval[-1, +1].
ASin(Number AS Float) AS Float or Asn(Number AS Float) AS FloatCalculates the radian measure of the angle at a given sine value. Note the periodicity of the sine function with the smallest period of 2π
Cos(Angle AS Float) AS FloatCalculates the cosine of an angle. The angle must be specified in radian measure! The function value is within the interval[-1, +1].
ACos(Number AS Float) AS Float or Acs(Number AS Float) AS FloatCalculates the radian measure of the angle at a given cosine value.
Tan(Angle AS Float)Calculates the tangent of an angle. The angle must be specified in radian measure!
ATan(Number AS Float) AS Float or Atn(Number AS Float) AS FloatCalculates the radian measure of the angle (interval[-π/2, +π/2]) to a given tangent value.
Mag(x AS Float, y AS Float)This function calculates the distance of the point P(x, y) in the Cartesian coordinate system from the coordinate origin O(0,0) with Sqr(x*x+y*y*y). It is the same function as Hyp().
Ang(x AS Float, y AS Float)This function calculates the arc tangent of the two variables x and y. This corresponds to the calculation of the arc tangent of x/y, except that the algebraic sign of both arguments are used to determine the quadrant of the result. The function returns the function value in radian measure, which is between -π and +π (inclusive). This is the same function as ATan2().
ASinh (Number AS Float) AS Float or Asnh(Number AS Float) AS FloatCalculates the hyperbolic arc sine to a given number.
Sinh(Number AS Float)Calculates the hyperbolic sine to a given number.
ACosh(Number AS Float) AS Float or Acsh(Number AS Float) AS FloatCalculates the hyperbolic arc cosine to a given number.
Cosh(Number AS Float) AS FloatCalculates the hyperbolic cosine to a given number.
ATan (Number AS Float) AS Float or Atnh(Number AS Float) AS FloatCalculates the hyperbolic arc tangent of a number.
Tan (Number AS Float)Calculates the hyperbolic tangent of a number.
ATan(y AS Float, x AS Float) AS Float or Atn2(y AS Float, x AS Float) AS FloatCalculates the arc tangent of the variable x and y. It corresponds to calculating the arc tangent of y/x, except that the sign of the two arguments are used to determine the quadrant of the result. The function returns a result between -π and +π (inclusive). Synonym for the function Ang().
Hyp(x AS Float, y AS Float) AS FloatSynonym for the function Mag(x, y)

Table 9.7.1: Overview of trigonometric functions

Hints:

Examples:

Print IIf(Tan(1.33) - Sin(Rad(50)) < 0, "Yes", "No!")
Print Format(Deg(ACos(0.4432)), "#.###°")
Print IIf(Mag(8, 6) > 9.8, "Yes.", "No.")
Print Sin(1)
Print "P(8|6) ---> P'("; Hyp(8, 6); "|"; Deg(Ang(8, 6)); "°)"
Print "The arc measurement 123° = "; Round(Rad(123), -3)
Print "Cos(Pi(7/3)) = "; Cos(Pi(7/3))
No!
63,692°
Yes.
0,8414709848079
P(8|6) ---> P'(10|36,87°)
The arc measurement Rad(123°) = 2,147
Yes - Cos(Pi(7/3)) = 0,5