Bezier filter

Apr 26, 2013 at 8:21 PM
Hi can someone guide me trhu what direction should i go to get a bezier filter?.

I searched all over but cannot find a way to draw a curve between two points instead of the normal straight line, basically i would like to add three points for example and the graph automaticaly draws a bezier curve between those points, can someone help me?

Right now i found a StepLineFilter wich does what is suposed to do and it works :) i would like to add a filter like that but instead of steps add those middle points in order to draw a curve.

Thanks in advance.
Apr 26, 2013 at 9:13 PM
Edited Apr 26, 2013 at 9:14 PM
Nevermind i did it myself :)
For anyone that is interested here is the filter, please take in mind that is still a little bit rought.
Part of the code i got from here : http://stackoverflow.com/questions/13940983/how-to-draw-bezier-curve-by-several-points
To use just do like this : LineGraph.Filters.Add(new BezierLineFilter());
class BezierLineFilter : PointsFilterBase
{
    public override List<Point> Filter(List<Point> points)
    {
        return GetBezierApproximation(points.ToArray(), 30);
    }

    public override void SetScreenRect(Rect screenRect)
    {
        lastX = screenRect.X + screenRect.Width;
    }

    List<Point> GetBezierApproximation(Point[] controlPoints, int outputSegmentCount)
    {
        List<Point> result = new List<Point>();

        if (controlPoints != null && controlPoints.Length > 1)
        {
            Point[] points = new Point[outputSegmentCount + 1];
            for (int i = 0; i <= outputSegmentCount; i++)
            {
                double t = (double)i / outputSegmentCount;
                points[i] = GetBezierPoint(t, controlPoints, 0, controlPoints.Length);
            }

            result = new List<Point>(points);
        }
        return result;
    }

    Point GetBezierPoint(double t, Point[] controlPoints, int index, int count)
    {
        if (count == 1)
            return controlPoints[index];
        var P0 = GetBezierPoint(t, controlPoints, index, count - 1);
        var P1 = GetBezierPoint(t, controlPoints, index + 1, count - 1);
        return new Point((1 - t) * P0.X + t * P1.X, (1 - t) * P0.Y + t * P1.Y);
    }
}