[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-gsl] Using GSL to draw a 2D B-Spline path using unevenly space

From: Patrick Alken
Subject: Re: [Help-gsl] Using GSL to draw a 2D B-Spline path using unevenly spaced points
Date: Fri, 13 Jun 2014 09:28:22 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0

The basic idea behind breakpoints is you want to have a sufficient
amount of data in between your breakpoints to properly constrain the
B-spline coefficients during the least-squares inversion. Also if you
know your function changes rapidly in some regions and not others, you
can add more knots to those areas.

If you have lots of (scattered) data in the whole interval, you can
start with uniform knots and see how it goes. If, however, your function
is sparsely sampled in some places you'll want to pick your breakpoints
to have enough data in each interval.

GSL does not currently support 2D B-splines. For 2D scattered data
interpolation, one method which isn't too difficult to code is radial
basis functions (see Numerical Recipes for an introduction). I know
someone is working on a GSL extension for RBFs but its not ready yet.


On 06/13/2014 12:56 AM, Michael Petrie wrote:
> Hi, my name's Michael, and I'm new to the mailing list, so forgive me if
> I'm asking this question in the wrong place.
> I'm trying to using the GNU Scientific Library (GSL) to draw a smooth path
> from A to B. I'm using an API that returns a small number (8 in this case)
> of irregularly spaced points (in red), that you can see picture [1].
> The purple points represent the points that I would like to see returned
> from GSL.
> Firstly, is this kind of 2D B-Spline shape obtainable by using GSL? I don't
> know much about B-Splines, let alone 2D B-Splines. I was able to get the
> B-Splines example at link [2] running and creating a smooth .ps file
> without problem, but that example uses uniform breakpoints with the
> following code:
>     /* use uniform breakpoints on [0, 15] */
>     gsl_bspline_knots_uniform(0.0, 15.0, bw);
> In my case, given that the data I'm given is erratic and not evenly spaced,
> would I have to use non-uniform knots? I tried using `gsl_bspline_knots()`,
> in order to use non uniform breakpoints within the following test code, but
> I'm really not sure if this is the right direction or not.
>     #define NCOEFFS 8 // not sure what this number should be - number of
> data points?
>     #define NBREAK   (NCOEFFS - 2)
>     const size_t nbreak = NBREAK;
>     int main (void) {
>         // (example code)...
>         gsl_vector *non_uniform = gsl_vector_alloc(nbreak);
>         // create some random breakpoint values
>         for (i=0; i<nbreak; i++) {
>             double val = gsl_ran_gaussian(r, 2.0);
>             printf("val: %f\n", val);
>             gsl_vector_set(non_uniform, i, val);
>         }
>         gsl_bspline_knots(non_uniform, bw);
>         // (more example code)...
>     }
> Further more, how would I translate the above example for drawing B-Splines
> in a 2D x/y coordinate space? If GNU Scientific Library is not suitable for
> this, could someone make a recommendation for a more suitable C/C++ library?
> Any help or pointers in the direction would be much appreciated.
>   [1]:
>   [2]:
> PS, I have also asked this question at Stack Overflow too:

reply via email to

[Prev in Thread] Current Thread [Next in Thread]