File Exchange

image thumbnail

NURBS Toolbox by D.M. Spink

version 1.0 (42.9 KB) by

NURBS Toolbox by D.M. Spink re-uploaded. The previous link has broken.

23 Ratings



View License

NURBS Toolbox official site is

% NURBS Toolbox.
% Version 1.0
% demos - NURBS demonstrations
% nrbmak - Construct a NURBS from control points and knots.
% nrbtform - Applying scaling, translation or rotation operators.
% nrbkntins - Knot insertion/refinement.
% nrbdegelev - Degree elevation.
% nrbderiv - NURBS representation of the derivative.
% nrbdeval - Evaluation of the NURBS derivative.
% nrbkntmult - Find the multiplilicity of a knot vector.
% nrbreverse - Reverse evaluation direction of the NURBS.
% nrbtransp - Swap U and V for NURBS surface.
% nrbline - Construct a straight line.
% nrbcirc - Construct a circular arc.
% nrbrect - Construct a rectangle.
% nrb4surf - Surface defined by 4 corner points.
% nrbeval - Evalution of NURBS curve or surface.
% nrbextrude - Extrude a NURBS curve along a vector.
% nrbrevolve - Construct surface by revolving a profile.
% nrbruled - Ruled surface between twp NURBS curves.
% nrbcoons - Construct Coons bilinearly blended surface patch.
% nrbplot - Plot NURBS curve or surface.
% bspeval - Evaluate a univariate B-Spline.
% bspderiv - B-Spline representation of the derivative
% bspkntins - Insert a knot or knots into a univariate B-Spline.
% bspdegelev - Degree elevation of a univariate B-Spline.
% vecnorm - Normalise the vectors.
% vecmag - Magnitaude of the vectors.
% vecmag2 - Squared Magnitude of the vectors.
% vecangle - Alternative to atan2 (0 <= angle <= 2*pi)
% vecdot - Dot product of two vectors.
% veccross - Cross product of two vectors.
% vecrotx - Rotation matrix around the x-axis.
% vecroty - Rotation matrix around the y-axis.
% vecrotz - Rotation matrix around the z-axis.
% vecscale - Scaling matrix.
% vectrans - Translation matrix.
% deg2rad - Convert degrees to radians.
% rad2deg - Convert radians to degrees.

Comments and Ratings (30)

I want to add elements to pnts like that
pnts = [0.5 1.5 4.5 3.0 7.5 6.0 8.5 10 12 14 16;
3.0 5.5 5.5 1.5 1.5 4.0 4.5 5.5 6.5 7.5 8.5;
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0];
but I got errors which is
Subscript indices must either be real positive integers or logicals.

Error in nrbplot (line 132)
p = nrbeval (nurbs, linspace (nurbs.knots(order), nurbs.knots(end-order+1), subd));

Error in deneme (line 82)
Do you have any suggestion?
My code given below.
% crv = nrbtestcrv;
pnts = [0.5 1.5 4.5 3.0 7.5 6.0 8.5;
3.0 5.5 5.5 1.5 1.5 4.0 4.5;
0.0 0.0 0.0 0.0 0.0 0.0 0.0];
crv = nrbmak(pnts,[0 0 0 1/4 1/2 3/4 3/4 1 1 1]);

% plot the control points
title('Arbitrary Test 2D Curve.');
hold on;

% plot the nurbs curve
hold off;

% plot the control points
title('Arbitrary Test 2D Curve.');
hold on;

% plot the nurbs curve
hold off;

great job.. thank you!!

zhao zhang

Thank you so much! This is very helpful for my research!

Zuowei Zhu

Great toolbox! Still learning it but it's of great help!

Second dérivatives of NURBS are missing


youhuo huang

Very useful toolbox, thank you very much!

Mi Chang

How to evaluate the disance between points and NURBS surface quickly?Is there a available function?Thanks a lot.

Raoul Herzog

There is a bug in findspan.m (infinite loop) if the evaluation point is at the end points with roundoff error.

Second dérivatives of NURBS are missing.

Is this project still active ?


Ocean (view profile)

I can't find which function could plot NUBRS surface,and always get erroes warnings

Thanks for the great NURBS adaption.
For one project i missed global approximation so i added my own function:

function [ CP,KV ] = globalInterp( Q,deg )
%GLOBALINTERPH Global Curveinterpolation
A = zeros(size(Q,1),size(Q,1));

% Centripetal Parametrisation
ub = paramCentripetal(Q);

% Centripetal Knotvector
KV = setKVcentripetal(size(Q,1),deg,ub)';

% Initialize Basis Matrix A
for i=2:size(Q,1)-1
span = findspan(size(Q,1),deg,ub(i),KV);
N = basisfun(span,ub(i),deg,KV);
l = span-deg;
for k=1:deg
A(i,l+k) = N(k);
% Set first and last Matrix Value
A(1,1) = 1.0;
A(size(Q,1),size(Q,1)) = 1.0;

% Solve
tmp = A\Q;

% Save Control Points
CP = [tmp(:,1) tmp(:,2) tmp(:,3)]';

function [ KV ] = setKVcentripetal( n,p,u )
%SETKVCENTRIPETAL Generates a Knot Vektor matching parametrization u
KV = zeros(n+p,1);

for i=size(KV,1)-p:size(KV,1)
KV(i) = 1.0;

for j=1:size(u,1)-p
tmp = 0.0;
for i=j:j+p-1
tmp = tmp+u(i);
KV(j+p) = tmp/p;

function [ uc ] = paramCentripetal( points )
%PARAMCENTRIPETAL Centripetal parametrization for given points
uc = zeros(size(points,1),1);

uc(1) = 0.0;
d = 0.0;
for i=2:size(uc,1)
d = d + pdist([points(i,:);points(i-1,:)]);
for i=2:size(uc,1)-1
uc(i) = uc(i-1) + pdist([points(i,:);points(i-1,:)])/d;
uc(size(uc,1)) = 1.0;

Maybe someone else will find this useful.

Greetings Christoph


Malte (view profile)

Hi Paul, this is great, thanks a lot! I am using it for several projects. However, for one application I would like to have the condition, that the 3D surface is tangential to every curve (contour). Is there such an option or where do I need to hook? Best regards!


There is a bug in nrbcoons.m, at line 82. all 'u's should be replaced with 'v's - the ruled surfaces and bilinear surfaces generated are equivalent but not in directly-addable representations in the current code.

mirui wang

I think we need a document to explain all the function and how to use.



good works.thanks

good work... thanks .


Erik (view profile)

When running democurve.m, execution get stuck in an infinite loop in findspan.m.

Can I find the original c-files somewhere, before conversion of all files to m-files?

Axel L

Axel L (view profile)


How to evaluate the second derivate of nurbs with this toolbox ?

Axel L

Axel L (view profile)


Thank for this useful toolbox.
How to get the rational basis function of nurbs with this toolbox ?

Daniel Lopes

Daniel Lopes (view profile)

There are bugs that make this toolbox uncompatible with the Nurbs2IGES


Li (view profile)

csg Chen

csg Chen

This toolbox is very useful. It can improve many problems in my applications. However, it seems some small bugs when I evaluate the derivative of nurbs curves/surfaces.
In the file "nrbderiv ":
this file call the function "bspderiv". If the weights of the original nurbs curve/surface are equal ( example: the weight = 1 at each vertex ), this weights of nurbs curve/surface vanish after call bspderiv in file nrbderiv.
Maybe, we should revise the file "nrbderiv" before calling the function "bspderiv" to preserve the original weights.


GAURAV (view profile)

I have a set of points say 300 something following the outline of cerebral aneurysm. I want to smooth this curve using the NURBS tool box provided here. How do i use this ? Where do I give my input? I just need a Bspline fitting to the data I have i.e. effectively to smooth the outline of the trace I have. Help me out..

Evgeny Pr

Evgeny Pr (view profile)

Where can I get C-implementation of this toolbox?


Oliver (view profile)

Very useful toolbox, thank you very much! Also very well commented and good examples.

MATLAB Release
MATLAB 7 (R14)

Inspired by: NURBS

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video