NetFabric.Numerics.Angle 1.0.0-beta04

Prefix Reserved
This is a prerelease version of NetFabric.Numerics.Angle.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package NetFabric.Numerics.Angle --version 1.0.0-beta04                
NuGet\Install-Package NetFabric.Numerics.Angle -Version 1.0.0-beta04                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NetFabric.Numerics.Angle" Version="1.0.0-beta04" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NetFabric.Numerics.Angle --version 1.0.0-beta04                
#r "nuget: NetFabric.Numerics.Angle, 1.0.0-beta04"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install NetFabric.Numerics.Angle as a Cake Addin
#addin nuget:?package=NetFabric.Numerics.Angle&version=1.0.0-beta04&prerelease

// Install NetFabric.Numerics.Angle as a Cake Tool
#tool nuget:?package=NetFabric.Numerics.Angle&version=1.0.0-beta04&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. For older versions of .NET, please use NetFabric.Angle instead.

using NetFabric.Numerics.Angle;

// Create angles
var degreesAngle = new Angle<Degrees, double>(45.0);
var radiansAngle = new Angle<Radians, float>(1.57f);
var gradiansAngle = new Angle<Gradians, decimal>(200.0m);
var revolutionsAngle = new Angle<Revolutions, double>(0.25);

// Perform angle operations
var sum = degreesAngle + Angle.ToDegrees<float, double>(radiansAngle);
var difference = Angle.ToRadians<decimal, float>(gradiansAngle) - Angle.ToRadians<double, float>(revolutionsAngle);
var product = 2.0 * degreesAngle;
var quotient = gradiansAngle / 100.0m;
var remainder = degreesAngle % 180.0;

// Compare angles
var areEqual = degreesAngle.Equals(Angle.ToDegrees<float, double>(radiansAngle));
var isGreater = gradiansAngle > Angle.ToGradians<double, decimal>(revolutionsAngle);

// Convert angles
var convertedToRadians = Angle.ToRadians<double, float>(degreesAngle);
var convertedToDegrees = Angle.ToDegrees<float, double>(radiansAngle);
var convertedToRevolution = Angle.ToRevolution(degreesAngle);

// Perform trigonometric calculations
var sineValue = Angle.Sin(radiansAngle);
var cosineValue = Angle.Cos(Angle.ToRadians(degreesAngle));
var tangentValue = Angle.Tan(radiansAngle);
var arcsineRadiansAngle = Angle.Asin(180.0);

// Reduce angles
var reducedAngle = Angle.Reduce(degreesAngle);
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 List<Angle<Degrees, double>> { degreesAngle, Angle.ToDegrees<float, double>(radiansAngle), Angle.ToDegrees<decimal, double>(gradiansAngle) };
var collectionSum = angleCollection.Sum();
var collectionAverage = angleCollection.Average();

Angle<TUnits, T> and AngleReduced<TUnits, T>

  • Angle<TUnits, T> represents an angle as a value of type T in the specified TUnits unit.
  • AngleReduced<TUnits, T> represents an angle as a value of type T in the specified TUnits 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 of IFloatingPoint<TSelf>.
  • The TUnits type can be any of the following types: Degrees, Radians, Gradians, Revolutions, or any other implementation of IAngleUnits<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 available, 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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

Add type conversion methods.
     Use math specific the internal types.