Registered Member
|
I've just seen that a unsupported module for interpolation exists in eigen.
I can include it with:
Now I have a VectorXd Xcoordinates, a VectorXd Ycoordinates, both made up of 100 points and describing a 2D curve and I wanna know the linear interpolation value given a X value. What do i have to define then? |
Registered Member
|
There is a SplineFitting<SplineType>::Interpolate method. You'd probably have to play around with that. I didn't find an example either.
'And all those exclamation marks, you notice? Five? A sure sign of someone who wears his underpants on his head.' ~Terry Pratchett
'It's funny. All you have to do is say something nobody understands and they'll do practically anything you want them to.' ~J.D. Salinger |
Registered Member
|
I've found this:
http://eigen.tuxfamily.org/dox-devel/unsupported/structEigen_1_1SplineFitting.html SplineFitting< > function; function.interpolate(const PointArrayType &pts, DenseIndex degree)) pts are the points in which the curve is interpolated, i guess. DenseIndex degree, is 1 for linear, 2 for square and so? But i can't understand if before that I need to define a Spline object. |
Registered Member
|
Sorry guys, I have been off the radar for quite some time. I took a little snippet from the unit tests I have written and hope that explains things a bit better.
There is no need to define a spline in advance. The PointArrayType must be an Eigen. IIRC, it can be either an Eigen::Matrix or an Eigen::Array. For a 2D spline it should have 2 rows and as many points as you want to fit. Unfortunately, there is not yet any support for approximate spline fitting but any patches would be welcome. In case you run into troubles, or find bugs, just let me know. Regards, Hauke |
Registered Member
|
Hi Hauke, I have started to use the unsupported module of Splines for interpolating in my code and it really works nice. I would like to know if there is any plan for supporting interpolation of surfaces (at least for 3D) or the module will only support curves. |
Registered Member
|
It's great to hear that the module is working nicely. I have not yet any plans to incorporate tensor product splines for surface interpolation. I would support volunteers who would like to implement them but that is all I can promise at the moment. Regrds, Hauke |
Registered Member
|
I need help with the next stuff:
I have the class Generic_Airplane which will be use Spline for 2D interpolation.
But the spline will be "populated" once I read some data from a file (so I can not construct it as the earlier post), this takes place within the constructor. If I define _spline there, just I can not compile it because:
How should I define it in the class? |
Registered Member
|
Hi noether,
the reason is obviously that I am not offering a default constructor. For splines of dynamic degree (as in your case), the solution is easy and I could also add the required default constructor. The idea would be to create a constant spline
and then you could initialize your spline in the Generic_Airplane constructor's initializer list like this
I cannot leave the control point and knot vector members of the spline uninitialized since then you have an invalid object which actually does not represent a spline. We probably do not want this. I will try to come up with some useful default constructors and for the time being the function I wrote above can be used as a quick workaround. Regards, Hauke |
Registered Member
|
I've added the missing default constructor. For splines of dynamic degree, it creates a constant, zero degree spline. For splines of fixed degree, it creates a constant spline of the requested degree. Default splines return 0 at all sites u.
That should fix your issue. Regards, Hauke |
Registered Member
|
Thank you very much Hauke, although finally I have solved following the next way: std::shared_ptr<Eigen::Spline<double, 2>> And when I have the spline built, just std::make_shared<Eigen::Spline<double, 2>> (spline); |
Registered Member
|
That's fine too, though you should consider the performance implications of std::shared_ptr (ref counting, thread safetiness machinery, see also [1]). I would suggest to either use nesting by value, as you did in your initial post or to use std::unique_ptr. Regards, Hauke [1] http://herbsutter.com/2012/06/05/gotw-1 ... culty-710/ |
Registered Member
|
Hi, Hauke and all involved.
Might be long after the last update here. I am playing around with the Spline class and have a simple question - how do I get a value of the 2d spline (say Spline2d) at the given x, which is not one of the provided points. I need a corresponding ChordLengths value, but have no idea how to get it. Thanks! |
Registered Member
|
Hi A32167,
The documentation can be found here: http://eigen.tuxfamily.org/dox-devel/unsupported/classEigen_1_1Spline.html#a785602b502f082dc3e715ffcb89295b4 You do no need a corresponding chord length value in order to evaluate the spline, you can use values of 'x' corresponding to chord length values but do not necessarily have to. Keep in mind, that x has to be from the interval [0;1]. Regards, Hauke |
Registered Member
|
Hi, Hauke. Thanks for answering!
I still don't quite get it. I'll give an example, using the post above. I want to use the Spline module for interpolating my data. Here I make a spline over y=x^2 defined on an array of 5 values : 1,2,3,4,6. While the spline works perfectly well, I don't understand how to get the value at x=5. Iterating through different values of chord values I can see, that for x=5 the spline gives me 25 as expected. Still it's probably not optimal to interpolate this way.
That shows
Last edited by A32167 on Mon Feb 25, 2013 1:24 pm, edited 1 time in total.
|
Registered Member
|
Hi again,
maybe this code example gives you an idea.
The best way to achieve what you want is to specify the knots which should be used for the interpolation by hand. Your initial code showed a spline which mapped from R^1 to R^2 while the function you wanted to fit the spline to maps from R^1 to R^1. Your way of fitting the curve is fine though I am not sure whether this was what you really wanted. I hope this helps a bit more, Hauke |
Registered users: abc72656, Bing [Bot], daret, Google [Bot], Sogou [Bot], Yahoo [Bot]