msteinbeck / tinyspline

ANSI C library for NURBS, B-Splines, and Bézier curves with interfaces for C++, C#, D, Go, Java, Javascript, Lua, Octave, PHP, Python, R, and Ruby.
MIT License
1.21k stars 207 forks source link

Decompose Bspline #224

Closed ajayre closed 1 year ago

ajayre commented 2 years ago

Hi, I have a Bezier curve of degree five

BSpline Spline = new BSpline((uint)_ControlPoints.Count / 2, 2, (uint)_Order - 1, BSplineType.CLAMPED);
Spline.ControlPoints = _ControlPoints;
Spline.Knots = _KnotVectors;
BSpline Beziers = Spline.ToBeziers();
...
if (Beziers.Degree == 5)
{
  ...

I need to break this up into Bezier curves of degree three or less. What do I need to call? Note that I am using the C# bindings generated by swig (which I don't really understand).

I see there is ts_bspline_to_beziers and this appears in the namespace TinySpline.tinysplinecsharp but how do I call it? Is there an example? Is it even the right function?

Thanks, Andy

msteinbeck commented 1 year ago

Hi @ajayre,

Hi, I have a Bezier curve of degree five [...] I need to break this up into Bezier curves of degree three or less.

You cannot reduce the degree of a spline with ToBeziers(). ToBeziers() simply "cuts" the spline into a sequence of connected Bezier curves where each Bezier curve has the same degree as the spline on which ToBeziers() was called. Degree reduction is not (yet) implemented in TinySpline. I did some research in the past and found the following paper: https://www.academia.edu/78438328/Degree_reduction_of_B%C3%A9zier_curves Section 2.1. presents an approach how to reduce the degree of a spline. Note, however, that the shape of a spline slightly changes when reducing its degree.

ajayre commented 1 year ago

Thanks for the pointer.

msteinbeck commented 1 year ago

I'm closing this issue. Don't hesitate to reopen it.