Giter VIP home page Giter VIP logo

b-spline's People

Contributors

ghsoares avatar pomax avatar thibauts avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

b-spline's Issues

Closed loop curves end point don't match start point

Hello! I've found this repository a couple of days ago when searching for nurbs curve implementations for C#, and I really liked how simple to understand the source code is and how easy is to use.

I've found a strange behaviour when using closed loop curves (repeating the first degree + 1 points at the end of the points array, as in the example), that the end point (t = 1) doesn't match start point (t = 0), actually it overshoots a bit in my tests (random generated 2D points with degree = 3, auto generated knots and weights).

To better illustrate, there's a video of drawing the spline in a canvas:
https://user-images.githubusercontent.com/43936806/125488852-15926514-f731-4173-929e-60493b18691d.mp4

Here's the files used for the test:
BSpline Test.zip

Rounding error causing 'out of bounds'

When this part of the codebase runs:

b-spline/index.js

Lines 36 to 40 in fdc3a31

var low = knots[domain[0]];
var high = knots[domain[1]];
t = t * (high - low) + low;
if(t < low || t > high) throw new Error('out of bounds');
it throws "Out of bounds" with valid values, because of a rounding error.

For example with these values, we get an error:

    let t = 1;
    
    const high = 83.50120024816177;
    const low = 1.545996015332399

    t = t * (high - low) + low;

    // t is now 83.50120024816178 - higher than high!= by 0.00000000000001

    if(t < low || t > high) throw new Error('out of bounds');

Docs increment by 0.01 causes rounding error preventing reaching clamped end

Just for anyone who ran into this issue, I was using the docs as a reference for this package (which is nice + simple to use with clear explanation + diagrams, thanks!) and ran into the issue that I was using a clamped knot vector to force the first/last curve points to exactly match the control points, BUT initially the final control point wasn't actually being included when I used the iteration loop as per the docs.

Turns out it's because the doc example was incrementing by 0.01 in the interpolation loop, but because of the numeric representation in JS, adding 0.01 100 times does NOT result in 1 ! (it's like 0.999). Because of this the last point (which would have been when t === 1) was not actually being hit.

For anyone that runs into this issue, just interpolate across an integer range (like 0 < t <= 100) and then /100 for the bspline funcs.

Hope that helps someone :)

Arc-length parameterization

It'd be great if there was a built-in option to reparameterize the spline based on arc length, so that it has continuous velocity. See this page for an explanation.

I've implemented this, I'd be happy to submit a pull request, if you think it'd be useful.

Oh and just wanted to say thanks for this; it's by far the easiest and nicest-looking path smoothing solution out there, at least for the sorts of things I do!

End tangents

I've just found your code and think that it is really good. Currently I'm trying to interpolate Autodesk's dxf file splines and your code comes really close except that Autodesk defines the end tangents of their splines and the length of their knot value fails your test on line 26.

I've been trying to figure out how to implement having the end tangent defined. Is there a way to add extra control points to have this work out correctly or should it be done in a different way?

I've been working on this for a while and still have not been able to figure it out. Please let me know if you know any way to interpolate this kind of spline.
Thank you

Here is an example of an Autodesk b-spline:

Autodesk spline cad drawing
spline

Interpolation using your b-spline library
spline_interpolation

Spline Properties
degree
3

starttangent
[-0.4138029443011841, 0.9103664774626047]
angle 1.9974238199217729 rad

endtangent
[0.8422714006615115, 0.539053696423367]
angle 0.5693131911006616 rad

controlpoints
[[2.399185827365247, 3.556238220882021], [1.79819140306395, 4.878425954344872], [3.793761079285986, 10.00772218210104], [9.597527631961984, 2.634051205137613], [-1.014386849068146, -0.7575600644211504], [-0.0580977089595729, 7.39060578138084], [1.891006407840181, 8.638032416132681]]
number of controlpoints 7

fitpoints
[[2.399185827365247, 3.556238220882021], [4.039879381831888, 7.592634753109687], [7.045397663022992, 3.861145872597061], [1.411865812287976, 1.712272898605353], [1.891006407840181, 8.638032416132681]]
number of fitpoints 5

knots
[0.0, 0.0, 0.0, 0.0, 4.357105955223939, 9.148467912325835, 15.17792362338283, 22.1202374022988, 22.1202374022988, 22.1202374022988, 22.1202374022988]
number of knots 11

weights
[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
number of weights 7

normalvector
(0.0, 0.0, 1.0)

is_closed
False

is_periodic
False

is_rational
False

is_planar
True

is_linear
False

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.