`SohCahToa` is a C# library designed to simplify trigonometric calculations with a focus on ease of use and precision.
$ dotnet add package 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.
Trig) or single precision (TrigF) for trigonometric operations.To integrate SohCahToa into your project, use the following NuGet command:
Install-Package SohCahToa
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}");
Trig ClassRise_RunPrimaryAngle, PrimaryAngle_RiseRun, ComplementaryAngle_PrimaryAngle, etc.TrigF ClassTrig but use float types, e.g., Rise_RunPrimaryAngle(float run, float primaryAngle).The library uses two naming conventions to accommodate different preferences:
{Output}_{Input1}{Input2}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{a|b|c}_{known_values}{known_angles}a = opposite side (rise), b = adjacent side (run), c = hypotenuseAA = primary angle, BB = complementary anglea_bAA(b, AA) - Same as Rise_RunPrimaryAngle(run, primaryAngle)c_ab(a, b) - Same as Hypotenuse_RiseRun(rise, run)AA_ab(a, b) - Same as PrimaryAngle_RiseRun(rise, run)// 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");
// 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");
// 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
// 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");
// 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);
Trig class when you need maximum precision for scientific calculations, engineering applications, or when working with large numbers where precision is critical.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.TrigF class is only available in .NET Standard 2.1 and later versions.Trig class (double precision)Trig and TrigF classesContributions are welcome! Please submit pull requests or open issues to discuss proposed changes or report bugs.
SohCahToa is released under the MIT License. See the LICENSE file in the repository for more details.