Module angle_sc::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.
    See: Pythagorean theorem
  • Calculate the cosine of an angle in Radians using the sine of the angle.
    Corrects cos π/4 to 1/√2.
  • Calculate the cosine of the difference of two angles: a - b.
    See: angle sum and difference identities.
  • Calculate the cosine of an angle from it’s sine and the sign of the cosine.
    See: swap_sin_cos.
  • Calculate the cosine of the sum of two angles: a + b.
    See: angle sum and difference identities.
  • 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.
    Note: calculates the cosine of the angle from its sine and overrides both the sine and cosine for π/4 to their correct values: 1/√2
  • Calculate the sine and cosine of an angle from the difference of a pair of values in Radians.
    Note: calculates the cosine of the angle from its sine and overrides the sine and cosine for π/4 to their correct values: 1/√2
  • Calculate the sine and cosine of an angle from a value in Degrees.
    Note: calculates the cosine of the angle from its sine and overrides the sine and cosine for ±30° and ±45° to their correct values.
  • Calculate the sine and cosine of an angle from the difference of a pair of values in Degrees.
    Note: calculates the cosine of the angle from its sine and overrides the sine and cosine for ±30° and ±45° to their correct values.
  • Calculate the sine of an angle in Radians.
    Corrects sin ±π/4 to ±1/√2.
  • Calculate the sine of the difference of two angles: a - b.
    See: angle sum and difference identities.
  • Calculate the sine of the sum of two angles: a + b.
    See: angle sum and difference identities.
  • Calculates the length of the other side in a right angled spherical triangle, given the length of one side and the hypotenuse.
    See: Spherical law of cosines
  • Calculate the length of the adjacent side of a right angled spherical triangle, given the cosine of the angle and length of the hypotenuse.
    See: Spherical law of cosines
  • Calculates the length of the hypotenuse in a right angled spherical triangle, given the length of both sides.
    See: Spherical law of cosines
  • Square of the cosine of half the Angle.
    See: Half-angle formulae
  • Square of the sine of half the Angle.
    See: Half-angle formulae
  • Swap the sine into the cosine of an angle and vice versa.
    Uses the identity sin2 + cos2 = 1.
    See: Pythagorean identities
  • The tangent of an angle.