NetFabric.Numerics.Angle
1.0.0-beta05
Prefix Reserved
See the version list below for details.
dotnet add package NetFabric.Numerics.Angle --version 1.0.0-beta05
NuGet\Install-Package NetFabric.Numerics.Angle -Version 1.0.0-beta05
<PackageReference Include="NetFabric.Numerics.Angle" Version="1.0.0-beta05" />
paket add NetFabric.Numerics.Angle --version 1.0.0-beta05
#r "nuget: NetFabric.Numerics.Angle, 1.0.0-beta05"
// Install NetFabric.Numerics.Angle as a Cake Addin #addin nuget:?package=NetFabric.Numerics.Angle&version=1.0.0-beta05&prerelease // Install NetFabric.Numerics.Angle as a Cake Tool #tool nuget:?package=NetFabric.Numerics.Angle&version=1.0.0-beta05&prerelease
NetFabric.Numerics.Angle
NetFabric.Numerics.Angle provides a strongly-typed implementation of an angle.
WARNING: NetFabric.Numerics.Angle makes use of generic math features only available in .NET 7 and C# 11. Make sure you are using a compatible version of the framework before using this library. For older versions of .NET, please use NetFabric.Angle instead.
using NetFabric.Numerics.Angle;
// Create angles
var degreesDoubleAngle = new Angle<Degrees, double>(45.0);
var radiansFloatAngle = new Angle<Radians, float>(1.57f);
var gradiansDecimalAngle = new Angle<Gradians, decimal>(200.0m);
var revolutionsDoubleAngle = new Angle<Revolutions, Half>((Half)0.25);
// Constants
var zeroDegreesDoubleAngle = Angle<Degrees, double>.Zero; // 0.0 degrees
var rightDegreesFloatAngle = Angle<Degrees, float>.Right; // 90.0f degrees
var straightRadiansDecimalAngle = Angle<Radians, decimal>.Straight; // π radians
var fullRevolutionsHalfAngle = Angle<Revolutions, Half>.Full; // 1 revolution
// Perform angle operations
var sum = degreesDoubleAngle + Angle<Degrees, double>.Right;
var difference = gradiansDecimalAngle - Angle<Gradians, decimal>.Right;
var product = 2.0 * degreesDoubleAngle;
var quotient = gradiansDecimalAngle / 100.0m;
var remainder = degreesDoubleAngle % 180.0;
// Compare angles
var areEqual = degreesDoubleAngle.Equals(Angle.ToDegrees(revolutionsDoubleAngle));
var isGreater = gradiansDecimalAngle > Angle<Gradians, decimal>.Right;
// Convert angles
var convertedToRadians = Angle.ToRadians(degreesDoubleAngle);
var convertedToDegrees = Angle.ToDegrees(radiansFloatAngle);
var convertedToRevolution = Angle.ToRevolutions(degreesDoubleAngle);
var convertToFloatChecked = Angle<Degrees, float>.CreateChecked(degreesDoubleAngle); // throws if value is out of range
var convertToFloatSaturating = Angle<Degrees, float>.CreateSaturating(degreesDoubleAngle); // saturates if value is out of range
var convertToFloatTruncating = Angle<Degrees, float>.CreateTruncating(degreesDoubleAngle); // truncates if value is out of range
// Perform trigonometric calculations
var sineValue = Angle.Sin(radiansFloatAngle);
var cosineValue = Angle.Cos(Angle.ToRadians(degreesDoubleAngle));
var tangentValue = Angle.Tan(radiansFloatAngle);
var arcsineRadiansAngle = Angle.Asin(sineValue);
// Reduce angles
var reducedAngle = Angle.Reduce(degreesDoubleAngle);
var quadrant = Angle.GetQuadrant(reducedAngle);
var reference = Angle.GetReference(reducedAngle);
// Classify angles
var isZeroAngle = Angle.IsZero(reducedAngle);
var isAcuteAngle = Angle.IsAcute(reducedAngle);
var isRightAngle = Angle.IsRight(reducedAngle);
var isObtuseAngle = Angle.IsObtuse(reducedAngle);
var isStraightAngle = Angle.IsStraight(reducedAngle);
// Calculate collection operations
var angleCollection = new[] { degreesDoubleAngle, Angle<Degrees, double>.Right, Angle<Degrees, double>.Straight };
var collectionSum = angleCollection.Sum();
var collectionAverage = angleCollection.Average();
Angle<TUnits, T> vs. AngleReduced<TUnits, T>
Angle<TUnits, T>
represents an angle as a value of typeT
in the specifiedTUnits
unit.AngleReduced<TUnits, T>
represents an angle as a value of typeT
in the specifiedTUnits
unit, reduced to the range[TUnits.Zero, TUnits.Full[
.- The
T
type can be any of the following types:float
,double
,decimal
, or any other implementation ofIFloatingPoint<TSelf>
. - The
TUnits
type can be any of the following types:Degrees
,Radians
,Gradians
,Revolutions
, or any other implementation ofIAngleUnits<TSelf>
.
Angle<TUnits, T>
can represent any angle value in the range [T.MinValue, T.MaxValue]
in the specified TUnits
unit. Some operations require the angle to be reduced to [TUnits.Zero, TUnits.Full[
.
To avoid the cost of reducing the angle every time, AngleReduced<TUnits, T>
can be used instead. It guarantees that the angle is already reduced.
An Angle<TUnits, T>
can be converted to an AngleReduced<TUnits, T>
using the Angle.Reduce()
method.
AngleReduced<TUnits, T>
can be implicitly converted to an Angle<TUnits, T>
.
Angle classification
NetFabric.Numerics.Angle provides a large number of methods to classify an angle: IsZero
, IsAcute
, IsRight
, IsObtuse
, IsStraight
, IsReflex
, IsOblique
, AreComplementary
, AreSupplementary
These methods are only available for AngleReduced<TUnits, T>
. When classifying a Angle<TUnits, T>
, reduce it first by using Angle.Reduce()
.
Trigonometry
NetFabric.Numerics.Angle provides a large number of trigonometric methods: Sin
, Cos
, Tan
, Sec
, Csc
, Cot
, Sinh
, Cosh
, Tanh
, Sech
, Csch
, Coth
, Asin
, Acos
, Atan
, Acot
, Asec
, Acsc
These methods are only available for angles in radians. When using an angle on any other unit, convert it first by using Angle.ToRadians()
.
Collections support
NetFabric.Numerics.Angle provides optimized operations on collections of angles: Sum
, Average
.
These operations are available for IEnumerable<Angle<TUnits, T>>
, Angle<TUnits, T>[]
, Memory<Angle<TUnits, T>>
, ReadOnlyMemory<Angle<TUnits, T>>
, Span<Angle<TUnits, T>>
, and ReadOnlySpan<Angle<TUnits, T>>
.
These operations use SIMD instructions when possible, ensuring high-performance calculations.
Credits
The following open-source projects are used to build and test this project:
License
This project is licensed under the MIT license. See the LICENSE file for more info.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
NuGet packages (3)
Showing the top 3 NuGet packages that depend on NetFabric.Numerics.Angle:
Package | Downloads |
---|---|
NetFabric.Numerics
Package Description |
|
NetFabric.Numerics.Geography
Package Description |
|
NetFabric.Numerics.Geodesy
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0-beta08 | 199 | 11/3/2023 |
1.0.0-beta07 | 85 | 10/24/2023 |
1.0.0-beta06 | 74 | 10/20/2023 |
1.0.0-beta05 | 97 | 6/11/2023 |
1.0.0-beta04 | 77 | 6/9/2023 |
1.0.0-beta03 | 75 | 5/24/2023 |
1.0.0-beta02 | 72 | 5/24/2023 |
1.0.0-beta01 | 73 | 5/23/2023 |
Fix README.