Class Trigonometry<T>
- Namespace
- Utils.Mathematics
- Assembly
- Utils.dll
Provides a base implementation of IAngleCalculator<T> for custom angle measures such as Degrees or Grades, along with default trigonometric/hyperbolic implementations.
public class Trigonometry<T> : IAngleCalculator<T> where T : struct, IFloatingPointIeee754<T>
Type Parameters
TA floating-point numeric type (e.g., float, double) implementing IFloatingPointIeee754<TSelf>.
- Inheritance
-
Trigonometry<T>
- Implements
- Inherited Members
- Extension Methods
Constructors
Trigonometry(T)
Creates a new Trigonometry<T> with the specified number of "units" representing a full revolution (perigon).
protected Trigonometry(T numberOfGraduation)
Parameters
numberOfGraduationTValue denoting the full rotation in the chosen measurement system (e.g., 360 for degrees, 400 for grads, π for radians).
Properties
Degree
A built-in calculator for Degrees (Perigon = 360).
public static IAngleCalculator<T> Degree { get; }
Property Value
Grade
A built-in calculator for Grads (Perigon = 400).
public static IAngleCalculator<T> Grade { get; }
Property Value
Graduation
Represents the conversion factor to radians. For non-radian systems, use this to convert angles to radians and call standard .NET trig methods.
public T Graduation { get; }
Property Value
- T
Perigon
Represents the full rotation (perigon) in this angle system. For example, 360 in degrees, 2π in radians, 400 in grads.
public T Perigon { get; }
Property Value
- T
Radian
A built-in calculator for Radians (Perigon = 2π).
public static IAngleCalculator<T> Radian { get; }
Property Value
RightAngle
Represents a right angle (one-quarter of Perigon). For example, 90 in degrees, π/2 in radians, 100 in grads.
public T RightAngle { get; }
Property Value
- T
StraightAngle
Represents a straight angle (half of Perigon). For example, 180 in degrees, π in radians, 200 in grads.
public T StraightAngle { get; }
Property Value
- T
Methods
Acos(T)
Computes the arccosine of the specified value and returns the
corresponding angle in the current measurement system.
public virtual T Acos(T value)
Parameters
valueTThe cosine ratio whose angle should be determined.
Returns
- T
An angle whose cosine is
value.
Acosh(T)
Computes the inverse hyperbolic cosine of the specified value.
public virtual T Acosh(T value)
Parameters
valueTThe hyperbolic cosine ratio whose angle should be determined.
Returns
- T
An angle whose hyperbolic cosine is
value.
Acot(T)
Computes the arccotangent of the specified value and returns the
corresponding angle in the current measurement system.
public virtual T Acot(T value)
Parameters
valueTThe cotangent ratio whose angle should be determined.
Returns
- T
An angle whose cotangent is
value.
Acot2(T, T)
Analogous to Atan2(T, T) but for the cotangent.
Internally computed as atan2(y, x).
public virtual T Acot2(T x, T y)
Parameters
xTyT
Returns
- T
Acoth(T)
Computes the inverse hyperbolic cotangent of the specified value.
public virtual T Acoth(T value)
Parameters
valueTThe hyperbolic cotangent ratio whose angle should be determined.
Returns
- T
An angle whose hyperbolic cotangent is
value.
Acsc(T)
Computes the arccosecant of the specified value and returns the
corresponding angle in the current measurement system.
public virtual T Acsc(T value)
Parameters
valueTThe cosecant ratio whose angle should be determined.
Returns
- T
An angle whose cosecant is
value.
Acsch(T)
Computes the inverse hyperbolic cosecant of the specified value.
public virtual T Acsch(T value)
Parameters
valueTThe hyperbolic cosecant ratio whose angle should be determined.
Returns
- T
An angle whose hyperbolic cosecant is
value.
AddAngles(T, T)
Adds two angles in this system, wrapping around if the sum exceeds Perigon.
public virtual T AddAngles(T angle1, T angle2)
Parameters
angle1Tangle2T
Returns
- T
AreEqual(T, T, T)
Determines whether two angles are equal within the specified tolerance, treating the angle
system as circular: e.g. in degrees, 359.999999 and 0.000001 are almost equal
(shortest distance 0.000002), not ~360 apart as a naive |a - b| would suggest.
public virtual bool AreEqual(T angle1, T angle2, T tolerance)
Parameters
angle1TFirst angle, expressed in this calculator's measurement system.
angle2TSecond angle, expressed in this calculator's measurement system.
toleranceTMaximum allowed angular distance between the two angles.
Returns
- bool
true if the shortest angular distance between
angle1andangle2is at mosttolerance; otherwise false.
AreEqualRounded(T, T, int)
Determines whether two angles round to the same value at the given decimal precision, after
normalizing both to [0, Perigon) so that wraparound values (e.g. in
degrees, 359.999999 and -0.000001) are compared consistently instead of as if they
were ~360 apart.
public virtual bool AreEqualRounded(T angle1, T angle2, int decimals)
Parameters
angle1TFirst angle, expressed in this calculator's measurement system.
angle2TSecond angle, expressed in this calculator's measurement system.
decimalsintNumber of decimal places to round to before comparing.
Returns
Asec(T)
Computes the arcsecant of the specified value and returns the
corresponding angle in the current measurement system.
public virtual T Asec(T value)
Parameters
valueTThe secant ratio whose angle should be determined.
Returns
- T
An angle whose secant is
value.
Asech(T)
Computes the inverse hyperbolic secant of the specified value.
public virtual T Asech(T value)
Parameters
valueTThe hyperbolic secant ratio whose angle should be determined.
Returns
- T
An angle whose hyperbolic secant is
value.
Asin(T)
Computes the arcsine of the specified value and returns the
corresponding angle in the current measurement system.
public virtual T Asin(T value)
Parameters
valueTThe sine ratio whose angle should be determined.
Returns
- T
An angle whose sine is
value.
Asinh(T)
Computes the inverse hyperbolic sine of the specified value.
public virtual T Asinh(T value)
Parameters
valueTThe hyperbolic sine ratio whose angle should be determined.
Returns
- T
An angle whose hyperbolic sine is
value.
Atan(T)
Computes the arctangent of the specified value and returns the
corresponding angle in the current measurement system.
public virtual T Atan(T value)
Parameters
valueTThe tangent ratio whose angle should be determined.
Returns
- T
An angle whose tangent is
value.
Atan2(T, T)
Computes the four-quadrant inverse tangent of x/y, returning an angle in the range
[-StraightAngle, StraightAngle].
This is analogous to atan2(x, y) in standard math libraries.
public virtual T Atan2(T x, T y)
Parameters
xTyT
Returns
- T
Atanh(T)
Computes the inverse hyperbolic tangent of the specified value.
public virtual T Atanh(T value)
Parameters
valueTThe hyperbolic tangent ratio whose angle should be determined.
Returns
- T
An angle whose hyperbolic tangent is
value.
Cos(T)
Computes the cosine of the supplied angle measured in the
current angle system.
public virtual T Cos(T angle)
Parameters
angleTAngle expressed in this calculator's measurement system.
Returns
- T
The cosine of
angle.
Cosh(T)
Computes the hyperbolic cosine of the supplied angle.
public virtual T Cosh(T angle)
Parameters
angleTAngle expressed in this calculator's measurement system.
Returns
- T
The hyperbolic cosine of
angle.
Cot(T)
Computes the cotangent of the supplied angle measured in the
current angle system.
public virtual T Cot(T angle)
Parameters
angleTAngle expressed in this calculator's measurement system.
Returns
- T
The cotangent of
angle.
Coth(T)
Computes the hyperbolic cotangent of the supplied angle.
public virtual T Coth(T angle)
Parameters
angleTAngle expressed in this calculator's measurement system.
Returns
- T
The hyperbolic cotangent of
angle.
Csc(T)
Computes the cosecant of the supplied angle measured in the
current angle system.
public virtual T Csc(T angle)
Parameters
angleTAngle expressed in this calculator's measurement system.
Returns
- T
The cosecant of
angle.
Csch(T)
Computes the hyperbolic cosecant of the supplied angle.
public virtual T Csch(T angle)
Parameters
angleTAngle expressed in this calculator's measurement system.
Returns
- T
The hyperbolic cosecant of
angle.
FromRadian(T)
Converts an angle from radians into the current measurement system.
public virtual T FromRadian(T angle)
Parameters
angleT
Returns
- T
Get(T)
Retrieves a cached calculator matching the specified perigon value or creates one on demand.
public static IAngleCalculator<T> Get(T perigon)
Parameters
perigonTThe angle span representing a full rotation in the desired system.
Returns
- IAngleCalculator<T>
An IAngleCalculator<T> configured for the requested perigon.
Normalize0To2Max(T)
Normalizes an angle into the range [0, Perigon), i.e., 0..360 for degrees, 0..2π for radians, 0..400 for grads.
public virtual T Normalize0To2Max(T angle)
Parameters
angleT
Returns
- T
NormalizeMinToMax(T)
Normalizes an angle into the range [ -StraightAngle, +StraightAngle ), i.e., -180..180 for degrees, -π..π for radians, -200..200 for grads.
public virtual T NormalizeMinToMax(T angle)
Parameters
angleT
Returns
- T
NormalizeRounded(T, int)
Normalizes angle to [0, Perigon) and rounds it to
decimals decimal places, wrapping a result that rounds up to exactly
Perigon back to zero. This is the canonical value AreEqualRounded(T, T, int)
compares internally; expose it separately so callers needing a hash-consistent representative
value (rather than a yes/no comparison) don't have to reimplement the wraparound handling.
public virtual T NormalizeRounded(T angle, int decimals)
Parameters
angleTThe angle to normalize and round, expressed in this calculator's measurement system.
decimalsintNumber of decimal places to round to.
Returns
- T
The normalized, rounded angle, always in
[0,Perigon).
Sec(T)
Computes the secant of the supplied angle measured in the
current angle system.
public virtual T Sec(T angle)
Parameters
angleTAngle expressed in this calculator's measurement system.
Returns
- T
The secant of
angle.
Sech(T)
Computes the hyperbolic secant of the supplied angle.
public virtual T Sech(T angle)
Parameters
angleTAngle expressed in this calculator's measurement system.
Returns
- T
The hyperbolic secant of
angle.
Sin(T)
Computes the sine of the supplied angle measured in the
current angle system.
public virtual T Sin(T angle)
Parameters
angleTAngle expressed in this calculator's measurement system.
Returns
- T
The sine of
angle.
Sinh(T)
Computes the hyperbolic sine of the supplied angle.
public virtual T Sinh(T angle)
Parameters
angleTAngle expressed in this calculator's measurement system.
Returns
- T
The hyperbolic sine of
angle.
SubtractAngles(T, T)
Subtracts angle2 from angle1 in this system, wrapping around if the result is negative or above Perigon.
public virtual T SubtractAngles(T angle1, T angle2)
Parameters
angle1Tangle2T
Returns
- T
Tan(T)
Computes the tangent of the supplied angle measured in the
current angle system.
public virtual T Tan(T angle)
Parameters
angleTAngle expressed in this calculator's measurement system.
Returns
- T
The tangent of
angle.
Tanh(T)
Computes the hyperbolic tangent of the supplied angle.
public virtual T Tanh(T angle)
Parameters
angleTAngle expressed in this calculator's measurement system.
Returns
- T
The hyperbolic tangent of
angle.
ToRadian(T)
Converts an angle to radians from the current measurement system.
public virtual T ToRadian(T angle)
Parameters
angleT
Returns
- T