Added Bezier Curves. Added Factorial and BinomialCoefficient to Functions.cs. Added Vector2d?.Perpendicular

This commit is contained in:
the_fiddler 2008-03-06 21:04:53 +00:00
parent 532594c1b2
commit c946bc6fb8
6 changed files with 51 additions and 4 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -1,8 +1,10 @@
#region --- License ---
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
* See license.txt for license info
/* Licensed under the MIT/X11 license.
* Copyright (c) 2006-2008 the OpenTK Team.
* This notice may not be removed from any source distribution.
* See license.txt for licensing detailed licensing details.
*
* Contributions by Andy Gill.
* Contributions by Andy Gill, James Talton and Georg Wächter.
*/
#endregion
@ -17,6 +19,32 @@ namespace OpenTK.Math
/// </summary>
public static class Functions
{
/// <summary>
/// Calculates the factorial of a given natural number.
/// </summary>
/// <param name="n">The number.</param>
/// <returns>n!</returns>
public static long Factorial(int n)
{
long result = 1;
for (; n > 1; n--)
result *= n;
return result;
}
/// <summary>
/// Calculates the binomial coefficient <paramref name="n"/> above <paramref name="k"/>.
/// </summary>
/// <param name="n">The n.</param>
/// <param name="k">The k.</param>
/// <returns>n! / (k! * (n - k)!)</returns>
public static long BinomialCoefficient(int n, int k)
{
return Factorial(n) / (Factorial(k) * Factorial(n - k));
}
/// <summary>
/// Returns an approximation of the inverse square root of left number.
/// </summary>
@ -43,6 +71,9 @@ namespace OpenTK.Math
public static double InverseSqrtFast(double x)
{
return InverseSqrtFast((float)x);
// TODO: The following code is wrong. Fix it, to improve precision.
#if false
unsafe
{
double xhalf = 0.5f * x;
@ -52,6 +83,7 @@ namespace OpenTK.Math
x = x * (1.5f - xhalf * x * x); // Perform left single Newton-Raphson step.
return x;
}
#endif
}
/// <summary>

View file

@ -2,7 +2,7 @@
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
* See license.txt for license info
*
* Contributions by Andy Gill.
* Contributions by Andy Gill, Georg ¤chter.
*/
#endregion
@ -145,6 +145,21 @@ namespace OpenTK.Math
}
}
#endregion
#region public Vector2 Perpendicular
/// <summary>
/// Gets the perpendicular vector.
/// </summary>
public Vector2 Perpendicular
{
get
{
return new Vector2(Y, -X);
}
}
#endregion
#region public void Normalize()

Binary file not shown.