ttk592 / spline Goto Github PK
View Code? Open in Web Editor NEWc++ cubic spline library
License: GNU General Public License v2.0
c++ cubic spline library
License: GNU General Public License v2.0
I found that the default result is the same as Python(scipy.interpolate.CubicSpline)'s natural
boundary condition.
But I don't know how to match the default result of Python(with default boundary condition not-a-knot
)
Hi, great work on the splines code. I just have a small issue i stumbled upon using it in my project. I'm trying to recreate this splines into my code. Thanks in advance! Here is the issue, the splines and my code:
int WorldGen(float Cont, float Eros, float PV ) {
int worldHeight = 0;
//Peakes & Valleys
std::vector<double> x1, y1;
x1.push_back(0.05f);
y1.push_back(0.f);
x1.push_back(0.1f);
y1.push_back(0.1f);
x1.push_back(0.325f);
y1.push_back(0.2f);
x1.push_back(0.5f);
y1.push_back(0.21f);
x1.push_back(0.65f);
y1.push_back(0.55f);
x1.push_back(0.9f);
y1.push_back(0.61f);
x1.push_back(1.f);
y1.push_back(0.65f);
tk::spline PVSpl;
PVSpl.set_points(x1, y1);
//Erosion
std::vector<double> x2, y2;
x2.push_back(0);
y2.push_back(1);
x2.push_back(0.15f);
y2.push_back(0.55f);
x2.push_back(0.3f);
y2.push_back(0.41f);
x2.push_back(0.32f);
y2.push_back(0.45f);
x2.push_back(0.45f);
y2.push_back(PVSpl.solve(PV)[0]);
x2.push_back(0.6f);
y2.push_back(0.11f);
x2.push_back(0.7f);
y2.push_back(0.11f);
x2.push_back(0.72f);
y2.push_back(0.28f);
x2.push_back(0.78f);
y2.push_back(0.28f);
x2.push_back(0.79f);
y2.push_back(0.11f);
x2.push_back(0.85f);
y2.push_back(0.05f);
x2.push_back(1.f);
y2.push_back(0.05f);
tk::spline ErosSpl;
ErosSpl.set_points(x2, y2);
//Continetalness
std::vector<double> x3, y3;
x3.push_back(0);
y3.push_back(1);
x3.push_back(0.09f);
y3.push_back(0.025f);
x3.push_back(0.345f);
y3.push_back(0.025f);
x3.push_back(0.385f);
y3.push_back(0.435f);
x3.push_back(0.515f);
y3.push_back(0.435f);
x3.push_back(0.525f);
y3.push_back(0.9f);
x3.push_back(0.55f);
y3.push_back(0.915f);
x3.push_back(0.72f);
y3.push_back(ErosSpl.solve(Eros)[0]);
x3.push_back(1.f);
y3.push_back(0.98f);
tk::spline ContSpl;
ContSpl.set_points(x3, y3);
worldHeight = ContSpl.solve(Cont)[0] * 100;
return worldHeight;
}
So task like the following:
4 points input
100 points output in between the first and the last one
When running make
in the examples folder I get:
g++ -I../../alglib/src -I../src -O2 -DNDEBUG -Wall -c interpol_alglib.cpp -o interpol_alglib.o
interpol_alglib.cpp:4:37: fatal error: interpolation.h: No such file or directory
#include "interpolation.h" // alglib
Looks like there is a missing file from alglib - perhaps document this better?
I use this to smooth the path, but the x of the path point is not necessarily monotonically increasing. How should I deal with it?
Hi,
very nice code. Looks like you have a typo for case 2 below. Shouldn't it be 2.0*m_b0
instead of 2.0*m_b0*h
?
if(x<m_x[0]) {
// extrapolation to the left
switch(order) {
case 1:
interpol=2.0*m_b0*h + m_c0;
break;
case 2:
interpol=2.0*m_b0*h;
break;
default:
interpol=0.0;
break;
}
Usage of spline as a member of class creates warning.
#include "spline/spline.h"
class CLASS {
tk::spline spline_;
}
Is anyone adding functionality to calculate the first derivative at the interior points?
I ran the code twice with 5 control points, in the second run I changed the fourth control point by a certain magnitude and observed that the global shape of the spline changed completely. I was hoping for more local control.
Hello. Thank you for this library. It is quite easy to use.
Your benchmarks shows that it takes 0.2sec to access spline 10^7 times.
But it takes 100 seconds in my case. I build a spline and include it as a member to my class.
Then in another method I access this spline about 10^7 times.
Please suggest an algorithm optimization.
Line 539 in 5894bea
Hello,
Is this library able to interpolate a closed spline curve ?
Thanks
Hi @ttk592,
I think this line is wrong: https://github.com/ttk592/spline/blob/master/src/spline.h#L332
Shouldn't it be: rhs[n-1] = 0.0;
?
May I suggest a change to a more liberal license (MIT, LGPL, Apache2...)? I see it more appropriate for the scope and the amount of code. Of course it's your choice.
I need to find the curve length , could you please give me some suggestoins.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.