User Tools

Site Tools


k9:k9.7:start

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:

  • To convert Cartesian coordinates P(x,y) into polar coordinates P'(r,φ) use the function Mag(x,y) to calculate the distance r of the point P(x,y) from the coordinate origin O(0,0) = pole and the function Ang(x,y) to calculate the (polar) angle φ between radius r and the reference axis (pole axis). The (relative) unit length must be defined on the reference axis in units of length.
  • You can do without the cosine function if you use the relationship sin²x + cos²x = 1 considering the quadrant relationships.

Examples:

  • Is the tangent of the angle with radian measure = 1.33 smaller than the sinus of 50°?
  • Calculate the angle ß (in degrees) whose cosine is 0.4432 and format the result with three decimal places and degrees!
  • Is the distance of point P(8|6) from the coordinate origin O(0,0) greater than 9,8 units of length?
  • Isn't sin(1) 90°?
  • Enter the polar coordinates P'(r,a°) for point P (8|6) in the Cartesian coordinate system. Calculate the radian measure of the angle φ = 123° with three decimal places.
  • Show that the cosine of (7/3)π is equal to 0.5!
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
The website uses a temporary session cookie. This technically necessary cookie is deleted when the browser is closed. You can find information on cookies in our privacy policy.
k9/k9.7/start.txt · Last modified: 11.02.2022 (external edit)

Page Tools