SohCahToa 3.0.0
dotnet add package SohCahToa --version 3.0.0
NuGet\Install-Package SohCahToa -Version 3.0.0
<PackageReference Include="SohCahToa" Version="3.0.0" />
<PackageVersion Include="SohCahToa" Version="3.0.0" />
<PackageReference Include="SohCahToa" />
paket add SohCahToa --version 3.0.0
#r "nuget: SohCahToa, 3.0.0"
#:package SohCahToa@3.0.0
#addin nuget:?package=SohCahToa&version=3.0.0
#tool nuget:?package=SohCahToa&version=3.0.0
SohCahToa
SohCahToa
is a C# library designed to simplify trigonometric calculations for right triangles with a focus on ease of use and precision. Named after the classic mnemonic SOH CAH TOA (Sine = Opposite/Hypotenuse, Cosine = Adjacent/Hypotenuse, Tangent = Opposite/Adjacent), this library provides intuitive methods for solving common trigonometry problems in engineering, construction, navigation, and educational applications.
Table of Contents
- Features
- Installation
- Quick Start
- API Overview
- Method Naming Convention
- Examples
- Performance Considerations
- Compatibility
- Contributing
- License
Features
- High Precision Calculations: Utilize double precision (
Trig
) or single precision (TrigF
) for trigonometric operations. - Static Methods: Direct access to trigonometric calculations without needing to instantiate classes.
- Comprehensive Coverage: Methods for calculating side lengths, primary and complementary angles in right triangles.
- Ease of Use: Intuitive method naming convention for quick understanding and implementation.
Installation
To integrate SohCahToa
into your project, use the following NuGet command:
Install-Package SohCahToa
Quick Start
Calculate the length of the opposite side of a right triangle given the adjacent side and the angle:
double run = 5;
double primaryAngle = 30;
double rise = Trig.Rise_RunPrimaryAngle(run, primaryAngle);
Console.WriteLine($"Rise: {rise}");
API Overview
Trig
Class
- Double Precision: For applications requiring high accuracy.
- Methods include
Rise_RunPrimaryAngle
,PrimaryAngle_RiseRun
,ComplementaryAngle_PrimaryAngle
, etc.
TrigF
Class
- Single Precision: Optimized for performance and memory efficiency (available in .NET Standard 2.1+).
- Methods mirror those of
Trig
but usefloat
types, e.g.,Rise_RunPrimaryAngle(float run, float primaryAngle)
.
Method Naming Convention
The library uses two naming conventions to accommodate different preferences:
Descriptive Method Names
- Pattern:
{Output}_{Input1}{Input2}
- Examples:
Rise_RunPrimaryAngle(run, angle)
- Calculate rise (opposite side) from run (adjacent side) and primary angleHypotenuse_RiseRun(rise, run)
- Calculate hypotenuse from rise and runPrimaryAngle_RiseRun(rise, run)
- Calculate primary angle from rise and run
Mathematical Aliases
- Pattern:
{a|b|c}_{known_values}{known_angles}
- Triangle notation:
a
= opposite side (rise),b
= adjacent side (run),c
= hypotenuse - Angle notation:
AA
= primary angle,BB
= complementary angle - Examples:
a_bAA(b, AA)
- Same asRise_RunPrimaryAngle(run, primaryAngle)
c_ab(a, b)
- Same asHypotenuse_RiseRun(rise, run)
AA_ab(a, b)
- Same asPrimaryAngle_RiseRun(rise, run)
Examples
Calculate Side Lengths
// Find the height of a building using distance and angle of elevation
double distanceFromBuilding = 50; // meters
double angleOfElevation = 30; // degrees
double buildingHeight = Trig.Rise_RunPrimaryAngle(distanceFromBuilding, angleOfElevation);
Console.WriteLine($"Building height: {buildingHeight:F2} meters");
Calculate Angles
// Find the angle of a roof slope given rise and run
double riseOfRoof = 3; // meters
double runOfRoof = 4; // meters
double roofAngle = Trig.PrimaryAngle_RiseRun(riseOfRoof, runOfRoof);
Console.WriteLine($"Roof angle: {roofAngle:F2} degrees");
Using Mathematical Aliases
// Same calculations using mathematical notation
double height = Trig.a_bAA(50, 30); // a = rise, b = run, AA = primary angle
double angle = Trig.AA_ab(3, 4); // AA = primary angle, a = rise, b = run
Comprehensive Navigation Example
// Calculate distance traveled when hiking up a mountain trail
double horizontalDistance = 1000; // meters
double elevation = 45; // degrees
double trailDistance = Trig.Hypotenuse_RunPrimaryAngle(horizontalDistance, elevation);
double verticalRise = Trig.Rise_RunPrimaryAngle(horizontalDistance, elevation);
Console.WriteLine($"Trail distance: {trailDistance:F2} meters");
Console.WriteLine($"Elevation gain: {verticalRise:F2} meters");
Single Precision for Performance-Critical Applications
// Using TrigF for game development or real-time calculations (.NET Standard 2.1+)
float playerX = 10.0f;
float playerY = 15.0f;
float distance = TrigF.Hypotenuse_RiseRun(playerY, playerX);
float angle = TrigF.PrimaryAngle_RiseRun(playerY, playerX);
Performance Considerations
- Use
Trig
class when you need maximum precision for scientific calculations, engineering applications, or when working with large numbers where precision is critical. - Use
TrigF
class when performance and memory efficiency are priorities, such as in game development, real-time simulations, or when processing large datasets where slight precision loss is acceptable. - Note:
TrigF
class is only available in .NET Standard 2.1 and later versions.
Compatibility
- .NET Standard 2.0+: Full support for
Trig
class (double precision) - .NET Standard 2.1+: Full support for both
Trig
andTrigF
classes - Angles: All angle inputs and outputs are in degrees (not radians)
- Thread Safety: All methods are static and thread-safe
Contributing
Contributions are welcome! Please submit pull requests or open issues to discuss proposed changes or report bugs.
License
SohCahToa
is released under the MIT License. See the LICENSE file in the repository for more details.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. 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 was computed. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
-
.NETStandard 2.1
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.