tinyspline icon indicating copy to clipboard operation
tinyspline copied to clipboard

Wrong BSpline representation after ToBeziers

Open artemishenkov opened this issue 8 months ago • 0 comments

Hi, I am using Tinyspline library(C#) to break down the BSpline(from dxf image) to beziers and put them into svg( image ) format. When I am trying to apply ToBeziers method on one particular spline which is supposed to be a circle Tinyspline breaks down it in a different shape. My spline: ControlPoints: 998.24, 702.13 997.58, 693.92 1005.01, 697.45 1012.44, 700.97 1005.67, 705.65 998.9, 710.33 998.24, 702.13 Knots: 0 0 0 2.0943951023932 2.0943951023932 4.188790204786389 4.188790204786389 6.283185307179588 6.283185307179588 6.283185307179588 Degree: 2 Dimension: 2 My code(C#): BSpline spline = new((uint)ControlPoints.Count, 2, (uint)Degree) { ControlPoints = points, Knots = Knots };

        BSpline beziers = spline.ToBeziers();

        var offset = (int)(spline.Order * spline.Dimension);
        var controls = beziers.ControlPoints;
        var length = controls.Count / offset;

        if (spline.Order == 4)
            for (int n = 0; n < length; n++)
                Beziers.Add(new GCubicBezier()
                {
                    Start = new(controls[n * offset], controls[n * offset + 1]),
                    Second = new(controls[n * offset + 2], controls[n * offset + 3]),
                    Third = new(controls[n * offset + 4], controls[n * offset + 5]),
                    End = new(controls[n * offset + 6], controls[n * offset + 7])
                });
        else if (spline.Order == 3)
            for (int n = 0; n < length; n++)
                Beziers.Add(new GQuadraticBezier
                {
                    Start = new(controls[n * offset], controls[n * offset + 1]),
                    Middle = new(controls[n * offset + 2], controls[n * offset + 3]),
                    End = new(controls[n * offset + 4], controls[n * offset + 5])
                });
        else if (spline.Order == 2)
            for (int n = 0; n < length; n++)
                Beziers.Add(new GSporadicBezier
                {
                    Start = new(controls[n * offset], controls[n * offset + 1]),
                    End = new(controls[n * offset + 2], controls[n * offset + 3])
                });

I would appreciate any help. Thank you.

artemishenkov avatar May 28 '24 01:05 artemishenkov