Skip to content

Instantly share code, notes, and snippets.

View dpellegr's full-sized avatar

Dario Pellegrini dpellegr

View GitHub Profile
@dpellegr
dpellegr / SplineBasis.cpp
Created September 28, 2020 13:03
C implementation of algorithm 2.1 and 2.2 from *The Nurbs Book*
#include <stdio.h>
#include <stdlib.h>
int findSpan( int n, int p, double u, double U[]) {
if (u == U[n+1]) return(n);
int pos = n/2;
int step = (pos < 4) ? 1 : pos / 2;
while (u < U[pos] || u >= U[pos+1]) {
pos += step * (( u >= U[pos]) * 2 - 1);
step = (step + 1)/2;