forum.alglib.net

ALGLIB forum
It is currently Sun Dec 22, 2024 7:08 pm

All times are UTC


Forum rules


1. This forum can be used for discussion of both ALGLIB-related and general numerical analysis questions
2. This forum is English-only - postings in other languages will be removed.



Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Spline1d
PostPosted: Tue Oct 25, 2011 8:53 am 
Offline

Joined: Tue Oct 25, 2011 8:07 am
Posts: 4
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!!!


Top
 Profile  
 
 Post subject: Re: Spline1d
PostPosted: Tue Oct 25, 2011 3:13 pm 
Offline

Joined: Tue Oct 25, 2011 8:07 am
Posts: 4
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 5575 times ]
Top
 Profile  
 
 Post subject: Re: Spline1d
PostPosted: Tue Oct 25, 2011 7:40 pm 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 927
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.


Top
 Profile  
 
 Post subject: Re: Spline1d
PostPosted: Mon Oct 31, 2011 10:39 am 
Offline

Joined: Tue Oct 25, 2011 8:07 am
Posts: 4
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 5561 times ]
Top
 Profile  
 
 Post subject: Re: Spline1d
PostPosted: Mon Oct 31, 2011 10:55 am 
Offline

Joined: Tue Oct 25, 2011 8:07 am
Posts: 4
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 5561 times ]
Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 24 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group