angle_sc

Module trig

Source
Expand description

The trig module contains functions for performing accurate trigonometry calculations.

The accuracy of the libm::sin function is poor for angles >= π/4 and the accuracy of the libm::cos function is poor for small angles, i.e., < π/4. So sin π/4 is explicitly set to 1/√2 and cos values are calculated from sin values using Pythagoras’ theorem.

The sincos function accurately calculates the sine and cosine of angles in radians by using remquo to reduce an angle into the range: -π/4 <= angle <= π/4; and its quadrant: along the positive or negative, x or y axis of the unit circle. The sincos_diff function reduces the round-off error of the difference of two angles in radians using the 2Sum algorithm.

The sincosd function is the degrees equivalent of sincos and sincosd_diff is the degrees equivalent of sincos_diff.

The sines and cosines of angles are represented by the UnitNegRange struct which ensures that they lie in the range: -1.0 <= value <= 1.0.

The functions arctan2 and arctan2d are the reciprocal of sincos and sincosd, transforming sine and cosines of angles into radians or degrees respectively.

The module contains the other trigonometric functions: tan, cot, sec and csc as functions taking sin and/or cos and returning an Option<f64> to protect against divide by zero.

The module also contains functions for:

Structs§

  • The UnitNegRange newtype an f64. A valid UnitNegRange value lies between -1.0 and +1.0 inclusive.

Constants§

Functions§

  • Accurately calculate an angle in Radians from its sine and cosine.
  • Accurately calculate an angle in Degrees from its sine and cosine.
  • Calculates the length of the other side in a right angled triangle, given the length of one side and the hypotenuse.
  • Calculate the cosine of an angle in Radians using the sine of the angle.
  • Calculate the cosine of the difference of two angles: a - b.
  • Calculate the cosine of an angle from it’s sine and the sign of the cosine.
  • Calculate the cosine of the sum of two angles: a + b.
  • The cotangent of an angle.
  • The cosecant of an angle.
  • The secant of an angle.
  • Calculate the sine and cosine of an angle from a value in Radians.
  • Calculate the sine and cosine of an angle from the difference of a pair of values in Radians.
  • Calculate the sine and cosine of an angle from a value in Degrees.
  • Calculate the sine and cosine of an angle from the difference of a pair of values in Degrees.
  • Calculate the sine of an angle in Radians.
  • Calculate the sine of the difference of two angles: a - b.
  • Calculate the sine of the sum of two angles: a + b.
  • Calculates the length of the other side in a right angled spherical triangle, given the length of one side and the hypotenuse.
  • Calculate the length of the adjacent side of a right angled spherical triangle, given the cosine of the angle and length of the hypotenuse.
  • Calculates the length of the hypotenuse in a right angled spherical triangle, given the length of both sides.
  • Square of the cosine of half the Angle.
  • Square of the sine of half the Angle.
  • Swap the sine into the cosine of an angle and vice versa.
  • The tangent of an angle.