TrueSync
TSMath.cs
1 /* Copyright (C) <2009-2011> <Thorben Linneweber, Jitter Physics>
2 *
3 * This software is provided 'as-is', without any express or implied
4 * warranty. In no event will the authors be held liable for any damages
5 * arising from the use of this software.
6 *
7 * Permission is granted to anyone to use this software for any purpose,
8 * including commercial applications, and to alter it and redistribute it
9 * freely, subject to the following restrictions:
10 *
11 * 1. The origin of this software must not be misrepresented; you must not
12 * claim that you wrote the original software. If you use this software
13 * in a product, an acknowledgment in the product documentation would be
14 * appreciated but is not required.
15 * 2. Altered source versions must be plainly marked as such, and must not be
16 * misrepresented as being the original software.
17 * 3. This notice may not be removed or altered from any source distribution.
18 */
19 
20 namespace TrueSync {
21 
25  public sealed class TSMath {
26 
30  public static FP Pi = FP.Pi;
31 
35  public static FP PiOver2 = FP.PiOver2;
36 
41  public static FP Epsilon = FP.Epsilon;
42 
46  public static FP Deg2Rad = FP.Deg2Rad;
47 
51  public static FP Rad2Deg = FP.Rad2Deg;
52 
58  #region public static FP Sqrt(FP number)
59  public static FP Sqrt(FP number) {
60  return FP.Sqrt(number);
61  }
62  #endregion
63 
70  #region public static FP Max(FP val1, FP val2)
71  public static FP Max(FP val1, FP val2) {
72  return (val1 > val2) ? val1 : val2;
73  }
74  #endregion
75 
82  #region public static FP Min(FP val1, FP val2)
83  public static FP Min(FP val1, FP val2) {
84  return (val1 < val2) ? val1 : val2;
85  }
86  #endregion
87 
95  #region public static FP Max(FP val1, FP val2,FP val3)
96  public static FP Max(FP val1, FP val2, FP val3) {
97  FP max12 = (val1 > val2) ? val1 : val2;
98  return (max12 > val3) ? max12 : val3;
99  }
100  #endregion
101 
109  #region public static FP Clamp(FP value, FP min, FP max)
110  public static FP Clamp(FP value, FP min, FP max) {
111  value = (value > max) ? max : value;
112  value = (value < min) ? min : value;
113  return value;
114  }
115  #endregion
116 
122  #region public static void Absolute(ref JMatrix matrix,out JMatrix result)
123  public static void Absolute(ref TSMatrix matrix, out TSMatrix result) {
124  result.M11 = FP.Abs(matrix.M11);
125  result.M12 = FP.Abs(matrix.M12);
126  result.M13 = FP.Abs(matrix.M13);
127  result.M21 = FP.Abs(matrix.M21);
128  result.M22 = FP.Abs(matrix.M22);
129  result.M23 = FP.Abs(matrix.M23);
130  result.M31 = FP.Abs(matrix.M31);
131  result.M32 = FP.Abs(matrix.M32);
132  result.M33 = FP.Abs(matrix.M33);
133  }
134  #endregion
135 
139  public static FP Sin(FP value) {
140  return FP.Sin(value);
141  }
142 
146  public static FP Cos(FP value) {
147  return FP.Cos(value);
148  }
149 
153  public static FP Tan(FP value) {
154  return FP.Tan(value);
155  }
156 
160  public static FP Asin(FP value) {
161  return FP.Asin(value);
162  }
163 
167  public static FP Acos(FP value) {
168  return FP.Acos(value);
169  }
170 
174  public static FP Atan(FP value) {
175  return FP.Atan(value);
176  }
177 
181  public static FP Atan2(FP y, FP x) {
182  return FP.Atan2(y, x);
183  }
184 
188  public static FP Floor(FP value) {
189  return FP.Floor(value);
190  }
191 
195  public static FP Ceiling(FP value) {
196  return value;
197  }
198 
203  public static FP Round(FP value) {
204  return FP.Round(value);
205  }
206 
211  public static int Sign(FP value) {
212  return FP.Sign(value);
213  }
214 
219  public static FP Abs(FP value) {
220  return FP.Abs(value);
221  }
222 
223  }
224 }
static void Absolute(ref TSMatrix matrix, out TSMatrix result)
Changes every sign of the matrix entry to &#39;+&#39;
Definition: TSMath.cs:123
static FP Min(FP val1, FP val2)
Gets the minimum number of two values.
Definition: TSMath.cs:83
static FP Tan(FP value)
Returns the tan of value.
Definition: TSMath.cs:153
static FP Rad2Deg
Radians to degree constant.
Definition: TSMath.cs:51
static FP Max(FP val1, FP val2, FP val3)
Gets the maximum number of three values.
Definition: TSMath.cs:96
static FP Cos(FP value)
Returns the cosine of value.
Definition: TSMath.cs:146
static FP Ceiling(FP value)
Returns the smallest integral value that is greater than or equal to the specified number...
Definition: TSMath.cs:195
static FP Round(FP value)
Rounds a value to the nearest integral value. If the value is halfway between an even and an uneven v...
Definition: TSMath.cs:203
static FP Atan2(FP y, FP x)
Returns the arc tan of coordinates x-y.
Definition: TSMath.cs:181
static FP Pi
PI constant.
Definition: TSMath.cs:30
static FP Deg2Rad
Degree to radians constant.
Definition: TSMath.cs:46
static FP Asin(FP value)
Returns the arc sine of value.
Definition: TSMath.cs:160
static FP Clamp(FP value, FP min, FP max)
Returns a number which is within [min,max]
Definition: TSMath.cs:110
Contains common math operations.
Definition: TSMath.cs:25
static FP Floor(FP value)
Returns the largest integer less than or equal to the specified number.
Definition: TSMath.cs:188
static FP PiOver2
PI over 2 constant.
Definition: TSMath.cs:35
static FP Max(FP val1, FP val2)
Gets the maximum number of two values.
Definition: TSMath.cs:71
static FP Sqrt(FP number)
Gets the square root.
Definition: TSMath.cs:59
static FP Abs(FP value)
Returns the absolute value of a Fix64 number. Note: Abs(Fix64.MinValue) == Fix64.MaxValue.
Definition: TSMath.cs:219
static FP Atan(FP value)
Returns the arc tan of value.
Definition: TSMath.cs:174
static FP Sin(FP value)
Returns the sine of value.
Definition: TSMath.cs:139
3x3 Matrix.
Definition: TSMatrix.cs:26
static FP Acos(FP value)
Returns the arc cosine of value.
Definition: TSMath.cs:167
static FP Epsilon
A small value often used to decide if numeric results are zero.
Definition: TSMath.cs:41
static int Sign(FP value)
Returns a number indicating the sign of a Fix64 number. Returns 1 if the value is positive...
Definition: TSMath.cs:211