diff --git a/README.md b/README.md index c81b70b..efbc3d3 100644 --- a/README.md +++ b/README.md @@ -1,49 +1,84 @@ # SohCahToa -[![NuGet version (iAutomateDesign.AutodeskAppStore)](https://buildstats.info/nuget/SohCahToa)](https://www.nuget.org/packages/SohCahToa) +[![NuGet version (SohCahToa)](https://buildstats.info/nuget/SohCahToa)](https://www.nuget.org/packages/SohCahToa) -Simplifies performing Trig calculations by providing descriptive function names. No more having to remember whether Sin, Cos, or Tan need to be used to get the value you are needing. +`SohCahToa` is a powerful C# library designed to simplify trigonometric calculations, making it an essential tool for engineering, educational software, and any application dealing with geometric data. With its focus on ease of use and precision, `SohCahToa` helps developers perform complex trigonometric calculations with minimal effort. -## How to Use +## Features -* Add a using statement for `SohCahToa` -* Call static functions within the `Trig` class +- **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 complimentary 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: + +```bash +Install-Package SohCahToa +``` + +## Quick Start + +Calculate the length of the opposite side of a right triangle given the adjacent side and the angle: ```csharp -var run = 10; -var rise = 15; -var hypotenuse = Trig.Hypotenuse_RiseRun(rise, run); +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`, `ComplimentaryAngle_PrimaryAngle`, etc. +### `TrigF` Class -### Triangle Side/Angle Nomenclature: +- **Single Precision**: Optimized for performance and memory efficiency. +- Methods mirror those of `Trig` but use `float` types, e.g., `Rise_RunPrimaryAngle(float run, float primaryAngle)`. -![Triangle Labels](https://i.imgur.com/EUrjY2m.png) +### Method Naming Convention -* Hypotenuse = c -* Run = b -* Rise = a -* Primary Angle = AA -* Complimentary Angle = BB +- **Descriptive Prefix**: The primary output or focus of the method (e.g., `Rise`, `Run`, `PrimaryAngle`). +- **Underscore Separator**: Enhances readability and method parsing. +- **Input Parameters**: Inputs or known quantities used for calculation. -**Angles are in degrees** +## Examples -### Function names follow the following structure: +### Calculate Side Lengths -**[Value to be Calculated]_[Input 1][Input 2]** +```csharp +double run = 5; +double primaryAngle = 30; +double rise = Trig.Rise_RunPrimaryAngle(run, primaryAngle); +``` -For Example: +### Calculate Angles -The function to use for calculating the hypotenuse of a triangle using the Rise and Run values would be `Hypotenuse_RiseRun()` +```csharp +double rise = 3; +double run = 4; +double primaryAngle = Trig.PrimaryAngle_RiseRun(rise, run); +``` -### Short Method Naming: +### Comprehensive Calculations + +```csharp +double run = 5; +double primaryAngle = 30; +double rise = Trig.Rise_RunPrimaryAngle(run, primaryAngle); +double complimentaryAngle = Trig.ComplimentaryAngle_PrimaryAngle(primaryAngle); +``` -Alternatively, there are functions that reference the values shown in the image above that could be used instead of using the descriptive names. +## Contributing -* Sides are named with lower case letters (a,b,c) +Contributions are welcome! Please submit pull requests or open issues to discuss proposed changes or report bugs. -* Angles are named with upper case double letters (AA, BB) +## License -The same calculated from above, calculating the hypotenuse using the Rise and Run values would be `c_ab()` \ No newline at end of file +`SohCahToa` is released under the MIT License. See the LICENSE file in the repository for more details. \ No newline at end of file diff --git a/src/SohCahToa/SohCahToa.csproj b/src/SohCahToa/SohCahToa.csproj index 37476c0..802b27d 100644 --- a/src/SohCahToa/SohCahToa.csproj +++ b/src/SohCahToa/SohCahToa.csproj @@ -1,6 +1,6 @@  - netstandard2.0 + netstandard2.1 Growler 2023 true diff --git a/src/SohCahToa/Trig.cs b/src/SohCahToa/Trig.cs index 52a4e1a..91e79d9 100644 --- a/src/SohCahToa/Trig.cs +++ b/src/SohCahToa/Trig.cs @@ -1,187 +1,282 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System; namespace SohCahToa { + /// + /// Provides methods for solving trigonometry problems related to right triangles. + /// Includes calculations for sides, angles, and hypotenuse based on given parameters. + /// public static class Trig { - //Triangle sides are represented with lower case letters a, b, c - //a = Short side "rise" - //b = Long side "depth" - //c = hypotenuse - //Triangle angles are represented with two capitol letters AA, BB - //AA = angle at lines b and c - //BB = angle at lines a and c - - //All trig functions are expressed as first what you are looking to solve. - //Example a function named "a_bAA" the first part of the function "a..." - //Tells us that we are looking to solve for side "a" - //The last part of the function "..._bAA" tells us that we know side "b" and angle "AA" - - - - - //********************* Solving For Side "a" ******************************* - //************************************************************************** - - public static double Rise_RunPrimaryAngle(double run, double primaryAngle) => a_bAA(run, primaryAngle); - public static double a_bAA(double b, double AA) + /// + /// Calculates the length of the side opposite to the primary angle (rise) given the adjacent side (run) and the primary angle. + /// + /// The length of the side adjacent to the primary angle. + /// The primary angle in degrees. + /// The length of the opposite side (rise). + public static double Rise_RunPrimaryAngle(double run, double primaryAngle) { - return b * Math.Tan(AA * (Math.PI / 180)); + return run * Math.Tan(ToRadians(primaryAngle)); } - - public static double Rise_HypotenusePrimaryAngle(double hypotenuse, double primaryAngle) => a_cAA(hypotenuse, primaryAngle); - public static double a_cAA(double c, double AA) + /// + /// Calculates the length of the side opposite to the primary angle (rise) given the hypotenuse and the primary angle. + /// + /// The length of the hypotenuse. + /// The primary angle in degrees. + /// The length of the opposite side (rise). + public static double Rise_HypotenusePrimaryAngle(double hypotenuse, double primaryAngle) { - return c * Math.Sin(AA * (Math.PI / 180)); + return hypotenuse * Math.Sin(ToRadians(primaryAngle)); } - public static double Rise_RunComplimentaryAngle(double run, double complimentaryAngle) => a_bBB(run, complimentaryAngle); - public static double a_bBB(double b, double BB) + /// + /// Calculates the length of the side opposite to the complimentary angle (rise) given the adjacent side (run) and the complimentary angle. + /// + /// The length of the side adjacent to the complimentary angle. + /// The complimentary angle in degrees. + /// The length of the opposite side (rise). + public static double Rise_RunComplimentaryAngle(double run, double complimentaryAngle) { - return b / Math.Tan(BB * (Math.PI / 180)); + return run / Math.Tan(ToRadians(complimentaryAngle)); } - public static double Rise_HypotenuseComplimentaryAngle(double hypotenuse, double complimentaryAngle) => a_cBB(hypotenuse, complimentaryAngle); - public static double a_cBB(double c, double BB) + /// + /// Calculates the length of the side opposite to the complimentary angle (rise) given the hypotenuse and the complimentary angle. + /// + /// The length of the hypotenuse. + /// The complimentary angle in degrees. + /// The length of the opposite side (rise). + public static double Rise_HypotenuseComplimentaryAngle(double hypotenuse, double complimentaryAngle) { - return c * Math.Cos(BB * (Math.PI / 180)); + return hypotenuse * Math.Cos(ToRadians(complimentaryAngle)); } - public static double Rise_RunHypotenuse(double run, double hypotenuse) => a_bc(run, hypotenuse); - public static double a_bc(double b, double c) + /// + /// Calculates the length of the side opposite to the primary angle (rise) given the adjacent side (run) and the hypotenuse. + /// + /// The length of the side adjacent to the primary angle. + /// The length of the hypotenuse. + /// The length of the opposite side (rise). + public static double Rise_RunHypotenuse(double run, double hypotenuse) { - return Math.Sqrt((Math.Pow(c, 2)) - (Math.Pow(b, 2))); + return Math.Sqrt(Math.Pow(hypotenuse, 2) - Math.Pow(run, 2)); } - //********************* Solving For Side "b" ******************************* - //************************************************************************** - - public static double Run_RisePrimaryAngle(double rise, double primaryAngle) => b_aAA(rise, primaryAngle); - public static double b_aAA(double a, double AA) + /// + /// Calculates the length of the adjacent side (run) given the opposite side (rise) and the primary angle. + /// + /// The length of the side opposite to the primary angle. + /// The primary angle in degrees. + /// The length of the adjacent side (run). + public static double Run_RisePrimaryAngle(double rise, double primaryAngle) { - return a / Math.Tan(AA * (Math.PI / 180)); + return rise / Math.Tan(ToRadians(primaryAngle)); } - public static double Run_HypotenusePrimaryAngle(double hypotenuse, double primaryAngle) => b_cAA(hypotenuse, primaryAngle); - public static double b_cAA(double c, double AA) + /// + /// Calculates the length of the adjacent side (run) given the hypotenuse and the primary angle. + /// + /// The length of the hypotenuse. + /// The primary angle in degrees. + /// The length of the adjacent side (run). + public static double Run_HypotenusePrimaryAngle(double hypotenuse, double primaryAngle) { - return c * Math.Cos(AA * (Math.PI / 180)); + return hypotenuse * Math.Cos(ToRadians(primaryAngle)); } - public static double Run_RiseComplimentaryAngle(double rise, double complimentaryAngle) => b_aBB(rise, complimentaryAngle); - public static double b_aBB(double a, double BB) + /// + /// Calculates the length of the adjacent side (run) given the opposite side (rise) and the complimentary angle. + /// + /// The length of the side opposite to the complimentary angle. + /// The complimentary angle in degrees. + /// The length of the adjacent side (run). + public static double Run_RiseComplimentaryAngle(double rise, double complimentaryAngle) { - return a * Math.Tan(BB * (Math.PI / 180)); + return rise * Math.Tan(ToRadians(complimentaryAngle)); } - public static double Run_HypotenuseComplimentaryAngle(double hypotenuse, double complimentaryAngle) => b_cBB(hypotenuse, complimentaryAngle); - public static double b_cBB(double c, double BB) + /// + /// Calculates the length of the adjacent side (run) given the hypotenuse and the complimentary angle. + /// + /// The length of the hypotenuse. + /// The complimentary angle in degrees. + /// The length of the adjacent side (run). + public static double Run_HypotenuseComplimentaryAngle(double hypotenuse, double complimentaryAngle) { - return c * Math.Sin(BB * (Math.PI / 180)); + return hypotenuse * Math.Sin(ToRadians(complimentaryAngle)); } - public static double Run_RiseHypotenuse(double rise, double hypotenuse) => b_ac(rise, hypotenuse); - public static double b_ac(double a, double c) + /// + /// Calculates the length of the adjacent side (run) given the opposite side (rise) and the hypotenuse. + /// + /// The length of the side opposite to the primary angle. + /// The length of the hypotenuse. + /// The length of the adjacent side (run). + public static double Run_RiseHypotenuse(double rise, double hypotenuse) { - return Math.Sqrt((Math.Pow(c, 2)) - (Math.Pow(a, 2))); + return Math.Sqrt(Math.Pow(hypotenuse, 2) - Math.Pow(rise, 2)); } - - //********************* Solving For Side "c" ******************************* - //************************************************************************** - - public static double Hypotenuse_RisePrimaryAngle(double rise, double primaryAngle) => c_aAA(rise, primaryAngle); - public static double c_aAA(double a, double AA) + /// + /// Calculates the length of the hypotenuse given the opposite side (rise) and the primary angle. + /// + /// The length of the side opposite to the primary angle. + /// The primary angle in degrees. + /// The length of the hypotenuse. + public static double Hypotenuse_RisePrimaryAngle(double rise, double primaryAngle) { - return a / Math.Sin(AA * (Math.PI / 180)); + return rise / Math.Sin(ToRadians(primaryAngle)); } - public static double Hypotenuse_RunPrimaryAngle(double run, double primaryAngle) => c_bAA(run, primaryAngle); - public static double c_bAA(double b, double AA) + /// + /// Calculates the length of the hypotenuse given the adjacent side (run) and the primary angle. + /// + /// The length of the side adjacent to the primary angle. + /// The primary angle in degrees. + /// The length of the hypotenuse. + public static double Hypotenuse_RunPrimaryAngle(double run, double primaryAngle) { - return b / Math.Cos(AA * (Math.PI / 180)); + return run / Math.Cos(ToRadians(primaryAngle)); } - public static double Hypotenuse_RiseComplimentaryAngle(double rise, double complimentaryAngle) => c_aBB(rise, complimentaryAngle); - public static double c_aBB(double a, double BB) + /// + /// Calculates the length of the hypotenuse given the opposite side (rise) and the complimentary angle. + /// + /// The length of the side opposite to the complimentary angle. + /// The complimentary angle in degrees. + /// The length of the hypotenuse. + public static double Hypotenuse_RiseComplimentaryAngle(double rise, double complimentaryAngle) { - return a / Math.Cos(BB * (Math.PI / 180)); + return rise / Math.Cos(ToRadians(complimentaryAngle)); } - public static double Hypotenuse_RunComplimentaryAngle(double run, double complimentaryAngle) => c_bBB(run, complimentaryAngle); - public static double c_bBB(double b, double BB) + /// + /// Calculates the length of the hypotenuse given the adjacent side (run) and the complimentary angle. + /// + /// The length of the side adjacent to the complimentary angle. + /// The complimentary angle in degrees. + /// The length of the hypotenuse. + public static double Hypotenuse_RunComplimentaryAngle(double run, double complimentaryAngle) { - return b / Math.Sin(BB * (Math.PI / 180)); + return run / Math.Sin(ToRadians(complimentaryAngle)); } - public static double Hypotenuse_RiseRun(double rise, double run) => c_ab(rise, run); - public static double c_ab(double a, double b) + /// + /// Calculates the length of the hypotenuse given the lengths of the other two sides. + /// + /// The length of the side opposite to the primary angle. + /// The length of the side adjacent to the primary angle. + /// The length of the hypotenuse. + public static double Hypotenuse_RiseRun(double rise, double run) { - return Math.Sqrt((Math.Pow(a, 2)) + (Math.Pow(b, 2))); + return Math.Sqrt(Math.Pow(rise, 2) + Math.Pow(run, 2)); } - - //********************* Solving For Angle "AA" ***************************** - //************************************************************************** - - public static double PrimaryAngle_ComplimentaryAngle(double complimentaryAngle) => AA_BB(complimentaryAngle); - public static double AA_BB(double BB) + /// + /// Calculates the primary angle given the complimentary angle. + /// + /// The complimentary angle in degrees. + /// The primary angle in degrees. + public static double PrimaryAngle_ComplimentaryAngle(double complimentaryAngle) { - return 90 - BB; + return 90 - complimentaryAngle; } - public static double PrimaryAngle_RiseRun(double rise, double run) => AA_ab(rise, run); - public static double AA_ab(double a, double b) + /// + /// Calculates the primary angle given the lengths of the opposite side (rise) and the adjacent side (run). + /// + /// The length of the side opposite to the primary angle. + /// The length of the side adjacent to the primary angle. + /// The primary angle in degrees. + public static double PrimaryAngle_RiseRun(double rise, double run) { - return Math.Atan((a / b)) * (180 / Math.PI); + return ToDegrees(Math.Atan(rise / run)); } - public static double PrimaryAngle_RiseHypotenuse(double rise, double hypotenuse) => AA_ac(rise, hypotenuse); - public static double AA_ac(double a, double c) + /// + /// Calculates the primary angle given the length of the opposite side (rise) and the hypotenuse. + /// + /// The length of the side opposite to the primary angle. + /// The length of the hypotenuse. + /// The primary angle in degrees. + public static double PrimaryAngle_RiseHypotenuse(double rise, double hypotenuse) { - return Math.Asin((a / c)) * (180 / Math.PI); + return ToDegrees(Math.Asin(rise / hypotenuse)); } - public static double PrimaryAngle_RunHypotenuse(double run, double hypotenuse) => AA_bc(run, hypotenuse); - public static double AA_bc(double b, double c) + /// + /// Calculates the primary angle given the length of the adjacent side (run) and the hypotenuse. + /// + /// The length of the side adjacent to the primary angle. + /// The length of the hypotenuse. + /// The primary angle in degrees. + public static double PrimaryAngle_RunHypotenuse(double run, double hypotenuse) { - return Math.Acos((b / c)) * (180 / Math.PI); + return ToDegrees(Math.Acos(run / hypotenuse)); } - - //********************* Solving For Angle "BB" ***************************** - //************************************************************************** - - public static double ComplimentaryAngle_PrimaryAngle(double primaryAngle) => BB_AA(primaryAngle); - public static double BB_AA(double AA) + /// + /// Calculates the complimentary angle given the primary angle. + /// + /// The primary angle in degrees. + /// The complimentary angle in degrees. + public static double ComplimentaryAngle_PrimaryAngle(double primaryAngle) { - return 90 - AA; + return 90 - primaryAngle; } - public static double ComplimentaryAngle_RiseRun(double rise, double run) => BB_ab(rise, run); - public static double BB_ab(double a, double b) + /// + /// Calculates the complimentary angle given the lengths of the opposite side (rise) and the adjacent side (run). + /// + /// The length of the side opposite to the complimentary angle. + /// The length of the side adjacent to the complimentary angle. + /// The complimentary angle in degrees. + public static double ComplimentaryAngle_RiseRun(double rise, double run) { - return Math.Atan((b / a)) * (180 / Math.PI); + return ToDegrees(Math.Atan(run / rise)); } - public static double ComplimentaryAngle_RiseHypotenuse(double rise, double hypotenuse) => BB_ac(rise, hypotenuse); - public static double BB_ac(double a, double c) + /// + /// Calculates the complimentary angle given the length of the opposite side (rise) and the hypotenuse. + /// + /// The length of the side opposite to the complimentary angle. + /// The length of the hypotenuse. + /// The complimentary angle in degrees. + public static double ComplimentaryAngle_RiseHypotenuse(double rise, double hypotenuse) { - return Math.Acos((a / c)) * (180 / Math.PI); + return ToDegrees(Math.Acos(rise / hypotenuse)); } - public static double ComplimentaryAngle_RunHypotenuse(double run, double hypotenuse) => BB_bc(run, hypotenuse); - public static double BB_bc(double b, double c) + /// + /// Calculates the complimentary angle given the length of the adjacent side (run) and the hypotenuse. + /// + /// The length of the side adjacent to the complimentary angle. + /// The length of the hypotenuse. + /// The complimentary angle in degrees. + public static double ComplimentaryAngle_RunHypotenuse(double run, double hypotenuse) { - return Math.Asin((b / c)) * (180 / Math.PI); + return ToDegrees(Math.Asin(run / hypotenuse)); } + /// + /// Converts an angle from degrees to radians. + /// + /// The angle in degrees. + /// The angle in radians. + private static double ToRadians(double angle) + { + return angle * (Math.PI / 180); + } + /// + /// Converts an angle from radians to degrees. + /// + /// The angle in radians. + /// The angle in degrees. + private static double ToDegrees(double angle) + { + return angle * (180 / Math.PI); + } } -} - +} \ No newline at end of file diff --git a/src/SohCahToa/TrigF.cs b/src/SohCahToa/TrigF.cs new file mode 100644 index 0000000..cb280e3 --- /dev/null +++ b/src/SohCahToa/TrigF.cs @@ -0,0 +1,282 @@ +using System; + +namespace SohCahToa +{ + /// + /// Provides methods for solving trigonometry problems related to right triangles. + /// Includes calculations for sides, angles, and hypotenuse based on given parameters. + /// + public static class TrigF + { + /// + /// Calculates the length of the side opposite to the primary angle (rise) given the length of the side adjacent to the primary angle (run) and the primary angle in degrees. + /// + /// The length of the side adjacent to the primary angle. + /// The primary angle in degrees. + /// The length of the opposite side (rise). + public static float Rise_RunPrimaryAngle(float run, float primaryAngle) + { + return run * MathF.Tan(ToRadians(primaryAngle)); + } + + /// + /// Calculates the length of the side opposite to the primary angle (rise) given the length of the hypotenuse and the primary angle in degrees. + /// + /// The length of the hypotenuse. + /// The primary angle in degrees. + /// The length of the opposite side (rise). + public static float Rise_HypotenusePrimaryAngle(float hypotenuse, float primaryAngle) + { + return hypotenuse * MathF.Sin(ToRadians(primaryAngle)); + } + + /// + /// Calculates the length of the side opposite to the complimentary angle (rise) given the length of the side adjacent to the complimentary angle (run) and the complimentary angle in degrees. + /// + /// The length of the side adjacent to the complimentary angle. + /// The complimentary angle in degrees. + /// The length of the opposite side (rise). + public static float Rise_RunComplimentaryAngle(float run, float complimentaryAngle) + { + return run / MathF.Tan(ToRadians(complimentaryAngle)); + } + + /// + /// Calculates the length of the side opposite to the complimentary angle (rise) given the length of the hypotenuse and the complimentary angle in degrees. + /// + /// The length of the hypotenuse. + /// The complimentary angle in degrees. + /// The length of the opposite side (rise). + public static float Rise_HypotenuseComplimentaryAngle(float hypotenuse, float complimentaryAngle) + { + return hypotenuse * MathF.Cos(ToRadians(complimentaryAngle)); + } + + /// + /// Calculates the length of the side opposite to the primary angle (rise) given the length of the side adjacent to the primary angle (run) and the length of the hypotenuse. + /// + /// The length of the side adjacent to the primary angle. + /// The length of the hypotenuse. + /// The length of the opposite side (rise). + public static float Rise_RunHypotenuse(float run, float hypotenuse) + { + return MathF.Sqrt(MathF.Pow(hypotenuse, 2) - MathF.Pow(run, 2)); + } + + /// + /// Calculates the length of the side adjacent to the primary angle (run) given the length of the side opposite to the primary angle (rise) and the primary angle in degrees. + /// + /// The length of the side opposite to the primary angle. + /// The primary angle in degrees. + /// The length of the adjacent side (run). + public static float Run_RisePrimaryAngle(float rise, float primaryAngle) + { + return rise / MathF.Tan(ToRadians(primaryAngle)); + } + + /// + /// Calculates the length of the side adjacent to the primary angle (run) given the length of the hypotenuse and the primary angle in degrees. + /// + /// The length of the hypotenuse. + /// The primary angle in degrees. + /// The length of the adjacent side (run). + public static float Run_HypotenusePrimaryAngle(float hypotenuse, float primaryAngle) + { + return hypotenuse * MathF.Cos(ToRadians(primaryAngle)); + } + + /// + /// Calculates the length of the side adjacent to the complimentary angle (run) given the length of the side opposite to the complimentary angle (rise) and the complimentary angle in degrees. + /// + /// The length of the side opposite to the complimentary angle. + /// The complimentary angle in degrees. + /// The length of the adjacent side (run). + public static float Run_RiseComplimentaryAngle(float rise, float complimentaryAngle) + { + return rise * MathF.Tan(ToRadians(complimentaryAngle)); + } + + /// + /// Calculates the length of the side adjacent to the complimentary angle (run) given the length of the hypotenuse and the complimentary angle in degrees. + /// + /// The length of the hypotenuse. + /// The complimentary angle in degrees. + /// The length of the adjacent side (run). + public static float Run_HypotenuseComplimentaryAngle(float hypotenuse, float complimentaryAngle) + { + return hypotenuse * MathF.Sin(ToRadians(complimentaryAngle)); + } + + /// + /// Calculates the length of the side adjacent to the primary angle (run) given the length of the side opposite to the primary angle (rise) and the length of the hypotenuse. + /// + /// The length of the side opposite to the primary angle. + /// The length of the hypotenuse. + /// The length of the adjacent side (run). + public static float Run_RiseHypotenuse(float rise, float hypotenuse) + { + return MathF.Sqrt(MathF.Pow(hypotenuse, 2) - MathF.Pow(rise, 2)); + } + + /// + /// Calculates the length of the hypotenuse given the length of the side opposite to the primary angle (rise) and the primary angle in degrees. + /// + /// The length of the side opposite to the primary angle. + /// The primary angle in degrees. + /// The length of the hypotenuse. + public static float Hypotenuse_RisePrimaryAngle(float rise, float primaryAngle) + { + return rise / MathF.Sin(ToRadians(primaryAngle)); + } + + /// + /// Calculates the length of the hypotenuse given the length of the side adjacent to the primary angle (run) and the primary angle in degrees. + /// + /// The length of the side adjacent to the primary angle. + /// The primary angle in degrees. + /// The length of the hypotenuse. + public static float Hypotenuse_RunPrimaryAngle(float run, float primaryAngle) + { + return run / MathF.Cos(ToRadians(primaryAngle)); + } + + /// + /// Calculates the length of the hypotenuse given the length of the side opposite to the complimentary angle (rise) and the complimentary angle in degrees. + /// + /// The length of the side opposite to the complimentary angle. + /// The complimentary angle in degrees. + /// The length of the hypotenuse. + public static float Hypotenuse_RiseComplimentaryAngle(float rise, float complimentaryAngle) + { + return rise / MathF.Cos(ToRadians(complimentaryAngle)); + } + + /// + /// Calculates the length of the hypotenuse given the length of the side adjacent to the complimentary angle (run) and the complimentary angle in degrees. + /// + /// The length of the side adjacent to the complimentary angle. + /// The complimentary angle in degrees. + /// The length of the hypotenuse. + public static float Hypotenuse_RunComplimentaryAngle(float run, float complimentaryAngle) + { + return run / MathF.Sin(ToRadians(complimentaryAngle)); + } + + /// + /// Calculates the length of the hypotenuse given the lengths of the other two sides (rise and run). + /// + /// The length of the side opposite to the primary angle. + /// The length of the side adjacent to the primary angle. + /// The length of the hypotenuse. + public static float Hypotenuse_RiseRun(float rise, float run) + { + return MathF.Sqrt(MathF.Pow(rise, 2) + MathF.Pow(run, 2)); + } + + /// + /// Calculates the primary angle in degrees given the complimentary angle in degrees. + /// + /// The complimentary angle in degrees. + /// The primary angle in degrees. + public static float PrimaryAngle_ComplimentaryAngle(float complimentaryAngle) + { + return 90 - complimentaryAngle; + } + + /// + /// Calculates the primary angle in degrees given the lengths of the opposite side (rise) and the adjacent side (run). + /// + /// The length of the side opposite to the primary angle. + /// The length of the side adjacent to the primary angle. + /// The primary angle in degrees. + public static float PrimaryAngle_RiseRun(float rise, float run) + { + return ToDegrees(MathF.Atan(rise / run)); + } + + /// + /// Calculates the primary angle in degrees given the length of the opposite side (rise) and the hypotenuse. + /// + /// The length of the side opposite to the primary angle. + /// The length of the hypotenuse. + /// The primary angle in degrees. + public static float PrimaryAngle_RiseHypotenuse(float rise, float hypotenuse) + { + return ToDegrees(MathF.Asin(rise / hypotenuse)); + } + + /// + /// Calculates the primary angle in degrees given the length of the adjacent side (run) and the hypotenuse. + /// + /// The length of the side adjacent to the primary angle. + /// The length of the hypotenuse. + /// The primary angle in degrees. + public static float PrimaryAngle_RunHypotenuse(float run, float hypotenuse) + { + return ToDegrees(MathF.Acos(run / hypotenuse)); + } + + /// + /// Calculates the complimentary angle in degrees given the primary angle in degrees. + /// + /// The primary angle in degrees. + /// The complimentary angle in degrees. + public static float ComplimentaryAngle_PrimaryAngle(float primaryAngle) + { + return 90 - primaryAngle; + } + + /// + /// Calculates the complimentary angle in degrees given the lengths of the opposite side (rise) and the adjacent side (run). + /// + /// The length of the side opposite to the complimentary angle. + /// The length of the side adjacent to the complimentary angle. + /// The complimentary angle in degrees. + public static float ComplimentaryAngle_RiseRun(float rise, float run) + { + return ToDegrees(MathF.Atan(run / rise)); + } + + /// + /// Calculates the complimentary angle in degrees given the length of the opposite side (rise) and the hypotenuse. + /// + /// The length of the side opposite to the complimentary angle. + /// The length of the hypotenuse. + /// The complimentary angle in degrees. + public static float ComplimentaryAngle_RiseHypotenuse(float rise, float hypotenuse) + { + return ToDegrees(MathF.Acos(rise / hypotenuse)); + } + + /// + /// Calculates the complimentary angle in degrees given the length of the adjacent side (run) and the hypotenuse. + /// + /// The length of the side adjacent to the complimentary angle. + /// The length of the hypotenuse. + /// The complimentary angle in degrees. + public static float ComplimentaryAngle_RunHypotenuse(float run, float hypotenuse) + { + return ToDegrees(MathF.Asin(run / hypotenuse)); + } + + /// + /// Converts an angle from degrees to radians. + /// + /// The angle in degrees. + /// The angle in radians. + private static float ToRadians(float angle) + { + return angle * (MathF.PI / 180); + } + + /// + /// Converts an angle from radians to degrees. + /// + /// The angle in radians. + /// The angle in degrees. + private static float ToDegrees(float angle) + { + return angle * (180 / MathF.PI); + } + } +} \ No newline at end of file