andrewwillmott / splines-lib Goto Github PK
View Code? Open in Web Editor NEWLibrary of cubic spline utilities
License: The Unlicense
Library of cubic spline utilities
License: The Unlicense
I found a little typo which causes an infinitely look when I do interesections of 3D splines that are on the z-plane. (eg Z=0)
Line 76 in 9c56e32
The check should be d.z > t;
Can you show an example simply computing f.e. a cubic spline from points? Accoring to the test example there come always wrong results with index = -1 during the query:
int cnt = getcount(); // point count
Vec2f* in = new Vec2f[cnt]; // input points
cSpline2* splines = new cSpline2[cnt + 1]; // splines
// Make vector
for (int i = 0; i < cnt; i++) { in[i].x = pt[i].getx(); in[i].y = p[i].gety(); }
// Splines
int numSplines = SplinesFromPoints(cnt, in, cnt + 1, splines);
// Query points from vector
for(int i = 0; i < cnt; i++)
{
int index;
float t = FindClosestPoint(in[i], cnt, splines, &index);
Vec2f cp = Position(splines[index], t);
}
delete[] in;
delete[] splines;
How can I divide multiple spline by length? I came up this code, but it seems not correct.
I divide splines by t
, but Len(spline, 0.0f, 0.1f) != Len(spline, 0.1f, 0.2f)
, because t and length are not linear.
Please help.
float lengths[numSplines];
float remainLengths[numSplines];
for (int i = 0; i < numSplines; ++i) {
lengths[i] = SplineLib::Length(splines[i], 0.01f);
remainLengths[i] = lengths[i];
}
int splineIndex = 0;
float ts = 0.0f;
auto pushPoint = [&]() {
dstPoints.emplace_back(Position(splines[splineIndex], ts));
dstTangents.emplace_back(Velocity(splines[splineIndex], ts));
};
// push start point
pushPoint();
while (splineIndex < numSplines) {
float step = space;
loop:
if (remainLengths[splineIndex] - step > 0) {
remainLengths[splineIndex] -= step;
ts += step / lengths[splineIndex];
pushPoint();
} else {
step = step - remainLengths[splineIndex];
ts = 0.0f;
splineIndex++;
if (splineIndex >= numSplines) {
break;
} else {
goto loop;
}
}
}
Edit:
I use SplineLib::SubdivideForT
to make t and length close to linear. It produce much many splines and reduce performance a lot. Is there a better way to achieve this? Best regards!
Many thanks for your project. Now i am using SISL lib for my project by QT5. But it is not updated long time.
SISL :https://github.com/SINTEF-Geometry/SISL
Could you add the function in splines-lib project?
Best regards,
Looking forward to the version in javascript
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.