forum.alglib.net
http://forum.alglib.net/

Spline1d
http://forum.alglib.net/viewtopic.php?f=2&t=459
Page 1 of 1

Author:  TITAMIN [ Tue Oct 25, 2011 8:53 am ]
Post subject:  Spline1d

Hello.
I have a question about spline.

i wrote next code but it crashes

spline1dinterpolant _spline;
real_1d_array _x;
real_1d_array _y;

double _xArray[_count];
double _yArray[_count];

for(int i = 0; i < _count; i++)
{
_xArray[i] = x; //x,y - this is just array of all touches
// it does not control points, it's just array points from system moveEvent
_yArray[i] = y;
}

ae_int_t length = _count;
_x.setcontent(length, _xArray);
_y.setcontent(length, _yArray);
spline1dbuildcubic(_x, _y, _spline);

for (double X = _xArray[0]; i < 768; i += 0.5) {

double Y = spline1dcalc(_spline, X);
paint(X,Y);
}

It crashes to the creation of a spline.
maby firstly i have to calculate control points ??? or not ???
And if i must calculate it, is here method for calculate it or it does like that :

P12(t) = (1-t)P1 + tP2
P23(t) = (1-t)P2 + tP3
P34(t) = (1-t)P3 + tP4
P1223(t) = (1-t)^2P1 + 2t(t-1)P2 + t^2P3
P2334(t) = (1-t)^2P2 + 2t(t-1)P3 + t^2P4
P(t) = (1-t)^3P1 + 3(1-t)^2tP2 + 3(1-t)t^2P3 + t^3P4

ok as a result my first and main question: spline1dbuildcubic(_x, _y, _spline); what is that "_x and _y", is it control points or not (just some array of points and spline calculate all itself)?

thanks in advance!!!

Author:  TITAMIN [ Tue Oct 25, 2011 3:13 pm ]
Post subject:  Re: Spline1d

next question... how can i set direction ??? I mean that now all points takes just from left to the right side, without direction. for example i set x = {0, 10, 30, 40, 20, 15} - spline builds - 0 10 15 20 30 40 - why ? what i do wrong ???

Attachments:
Screen shot 2011-10-25 at 6.11.39 PM.png
Screen shot 2011-10-25 at 6.11.39 PM.png [ 33.57 KiB | Viewed 5579 times ]

Author:  Sergey.Bochkanov [ Tue Oct 25, 2011 7:40 pm ]
Post subject:  Re: Spline1d

That's because there are two kinds of splines: non-parametric and parametric ones. First kind of splines is used to perform interpolation - to connect two variables, x and y, with functional relation: y=y(x). It can generate smooth curves, but such curves can't make turns because for any X there is only one Y. The problem statement is quite different from one you want to solve.

Parametric splines, from the other side, can solve the problem you want to solve. They generate x(t) and y(t), where t is a "position" parameter. Take a look at pspline subpackage: http://www.alglib.net/translator/man/ma ... it_pspline You can start from Akima spline with uniform parameterization. It should be easy starting point.

Author:  TITAMIN [ Mon Oct 31, 2011 10:39 am ]
Post subject:  Re: Spline1d

Thanks !!! I've got it. But i still have issue: do i have to build "periodic" or non - periodic spline...
that's what i'm doing now :
Code:
   
pspline2interpolant pInter;
   
    double* tmpArray = new double[_count * 2];
   
    for (int i = 0; i < _count; i++)
    {
        tmpArray[(i * 2)] = _xArray[i];
        tmpArray[(i * 2) + 1] = _yArray[i];
    }
   
    real_2d_array _2dArray;
   
    _2dArray.setcontent(2, _count, tmpArray);

    pspline2build(_2dArray, _count, 1, 0, pInter);

and have this result :

Attachments:
Screen Shot 2011-10-31 at 12.35.47 PM.png
Screen Shot 2011-10-31 at 12.35.47 PM.png [ 16.11 KiB | Viewed 5565 times ]

Author:  TITAMIN [ Mon Oct 31, 2011 10:55 am ]
Post subject:  Re: Spline1d

my bad !!! I mixed up rows and columns ))) no it's looks like this: )))

Attachments:
Screen Shot 2011-10-31 at 12.54.26 PM.png
Screen Shot 2011-10-31 at 12.54.26 PM.png [ 18.85 KiB | Viewed 5565 times ]

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/