smrendererv3/SMCode/SM.Base/Utility/BezierCurve.cs
Michel Fedde 2aa12f8d25 27.09.2020
~ Moved Default-Shader to 2D to provied 2D-specific feature
~ Fixed UVs in Polygon
2020-09-27 11:58:14 +02:00

23 lines
No EOL
713 B
C#

using System;
namespace SM.Utility
{
public class BezierCurve
{
public static float Calculate(float t, params float[] points)
{
int pointAmount = points.Length;
int itterations = pointAmount - 1;
double x = Math.Pow(1 - t, itterations) * points[0];
for (int i = 1; i < itterations; i++)
{
if (i % 2 == 0) x += itterations * (1 - t) * Math.Pow(t, itterations - 1) * points[i];
else x += itterations * Math.Pow(1 - t, itterations - 1) * t * points[i];
}
x += Math.Pow(t, itterations) * points[pointAmount - 1];
return (float)x;
}
}
}