Coder Social home page Coder Social logo

bspline's Introduction

BSpline

A simple and fast uniform-knot BSpline curve implementation by javascript. Usually, BSpline's basis function is defined recursively by De Boor's algorithm. But this library includes pre-calculated uniform-knot BSpline basis. Thus, the library works very fast.

Usage:

var spline = new BSpline(points,degree,copy [optional]);
spline.calcAt(t);
  • points : The array of points. Array of any dimensional vector is OK.
  • degree : The degree of BSpline curve. degree should be 2,3,4 or 5.
  • copy : This is optional. If this is omitted, BSpline uses the points itself. If true, BSpline copies points so that changes of points don't affect the curve.
  • t : The parametor of BSpline. t is in [0,1]. If t = 0 then returns first point of points. If t = 1 then returns last point of points.

Example:

var points = [[1,2],[2,3],[3,4]];
var spline = new BSpline(points,3); //making BSpline
for(var t = 0;t<=1;t+=0.01){
    var p = spline.calcAt(t); 
    draw(p);
}

Demo is available here

For more information, please visit here

bspline's People

Contributors

tagussan 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

Watchers

 avatar

bspline's Issues

Really hoped to find a plain implementation, too

I've spent two days on google trying to find even a single decent implementation of B-splines that isn't either hardcoded, or doesn't actually connect all the control points (starting the curve away from the first control point instead of at the first control point, and ending short, too).

then I found your code, but unfortunately instead of a generic implementation, it's also hardcoded only for a handful of orders... I know it's been 2 years, but would you consider adding the slower, generic "works for any order you need" function as well, that properly draw the connected curve from the first to the last control point? =(

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.