Skip to content

Commit a5205ce

Browse files
author
Dominic Beger
committed
Add MathHelper class
1 parent 8e03dc1 commit a5205ce

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

SharpMath/MathHelper.cs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Author: Dominic Beger (Trade/ProgTrade) 2016
2+
3+
using System;
4+
5+
// ReSharper disable InconsistentNaming
6+
7+
namespace SharpMath
8+
{
9+
/// <summary>
10+
/// Provides constants and methods for logarithmic, trigonometric and other useful mathematical functions.
11+
/// </summary>
12+
public static class MathHelper
13+
{
14+
/// <summary>
15+
/// Represents the base of the natural logarithm.
16+
/// </summary>
17+
public const float E = (float) Math.E;
18+
19+
/// <summary>
20+
/// Represents the base-10 logarithm of e, the base of natural logarithms.
21+
/// </summary>
22+
public const float Log10E = 0.4342945f;
23+
24+
/// <summary>
25+
/// Represents the base-2 logarithm of e, the base of natural logarithms.
26+
/// </summary>
27+
public const float Log2E = 1.442695f;
28+
29+
/// <summary>
30+
/// Represents the ratio of the circumference of a circle to its diameter, specified by the constant, π.
31+
/// </summary>
32+
public const float Pi = (float) Math.PI;
33+
34+
/// <summary>
35+
/// Represents <see cref="Pi" /> over 2 (90 degrees).
36+
/// </summary>
37+
public const float PiOver2 = (float) (Math.PI/2.0);
38+
39+
/// <summary>
40+
/// Represents <see cref="Pi" /> over 4 (45 degrees).
41+
/// </summary>
42+
public const float PiOver4 = (float) (Math.PI/4.0);
43+
44+
/// <summary>
45+
/// Represents 2 <see cref="Pi" /> (360 degrees).
46+
/// </summary>
47+
public const float TwoPi = (float) (Math.PI*2.0);
48+
49+
/// <summary>
50+
/// Converts degrees to radians.
51+
/// </summary>
52+
/// <param name="degrees">The angle in degrees.</param>
53+
/// <returns>The angle in radians.</returns>
54+
public static double DegreesToRadians(double degrees)
55+
{
56+
return degrees*(Math.PI/180);
57+
}
58+
59+
/// <summary>
60+
/// Converts radians to degrees.
61+
/// </summary>
62+
/// <param name="radians">The angle in radians.</param>
63+
/// <returns>The angle in degrees.</returns>
64+
public static double RadiansToDegrees(double radians)
65+
{
66+
return radians*(180/Math.PI);
67+
}
68+
}
69+
}

0 commit comments

Comments
 (0)