File Exchange

## NURBS

version 1.0 (7.67 KB) by

Converted NURBS toolbox

Updated

The NURBS toolbox, created by Mark Spink, is a very useful tool. However, some of the routines were written in C. This is not necessarily a bad thing as long as you know how to compile them to mex files for your machine. If you don't want to mess with mex files, or you want to be able to edit the code and don't know anything about C, I've rewritten the C code in MATLAB. You can find the original toolbox at

The included files replace the following mex files with the m-file equivalent.

basisfun
bspeval
bspdegelev
bspderiv
bspkntins
findspan

In addition, I've included the translated C code in the comments, line for line.

This does not include every file in the NURBS toolbox, just the mex files. You will still want to download the toolbox and replace the mex files with the included files.

Jie Huang

### Jie Huang (view profile)

To avoid the infinite loop, please make sure that the curve parameter u belongs to knot vector span. @Jeff@Junquan Peng

Liutong

### Liutong (view profile)

The dependent NURBS Toolbox file has been removed from File Exchange.

Goitom tesfay

### Goitom tesfay (view profile)

how can i use this toolbox any one help.

Jeff

### Jeff (view profile)

Junquan Peng, I am also running into the infinite while loop within "findspan.m". Have you found a solution?

Junquan Peng

### Junquan Peng (view profile)

who knows how to avoid the infinite loop, always show busy.I am glad to hear your responce,thank you!

Junquan Peng

University

Excellent!

MAK P

### MAK P (view profile)

TCH Sven and Matthew, The Knot vector should have the property that if the NURB is of order n then the 1st n+1 should be 0 and the last n+1 should be 1.0

I am trying to implement using the cartesian coordinate as the control points and i am also facing the same problem of infinite loop
here is my code
x and y are control points
u = [0.0,0.0,0.0,0.0,0.10,.20,.30,.40,.50,.60,.70,.80,.90,1.0,1.0,1.0,1.0];
crv = nrbmak([x';y'],u);
plot(crv.coefs(1,:),crv.coefs(2,:),'bo')
title('Degree elevation of test curve by 1');
hold on;
plot(crv.coefs(1,:),crv.coefs(2,:),'b--');

% draw nurbs curve
nrbplot(crv,48);

Will be glad to see a quick response

TCH

### TCH (view profile)

Sven and Matthew, I think I have got a solution to avoid the infinite loop but I don't know why:
NEVER modify the first three 0's and the last three 1's points, they have to be 0's and 1's.
in the democurve script, the last try of the demonstration intend to touch the third zero (which will cause the inifinite loop) so in the democurve.m file the code:
% @forbidden code start
crv.knots(1)=0.1;
crv.knots(2)=0.1;
crv.knots(3)=0.1;
crv.knots(end-2)=0.1;
crv.knots(end-1)=0.1;
crv.knots(end)=0.1;
@ forbidden code end
are all forbidden code lines,

crv.knots(4)=0.1;
crv.knots(5)=0.1;
crv.knots(6)=0.1;
... ...
crv.knots(end-5)=0.1;
crv.knots(end-4)=0.1;
crv.knots(end-3)=0.1;
are the permissive code lines. Am I clear ? ? :-]

TCH

### TCH (view profile)

actually the original findspan function seems to be stuck as well. the pure matlab version of the package is also stuck and dropped into the infinite loop, for the time I have got no ideas about the phenomenon. *~*

Matthew Schroeder

### Matthew Schroeder (view profile)

I'm experiencing the same problem as Sven. Any idea what might be causing this?

Sven

### Sven (view profile)

Is anyone else having fundamental problems with these .m files?
I've gotten the original toolbox, remove all mex/dll files from it, then put in the .m files here.

Anything (such as democurve, nrbplot, etc) gets stuck in an infinite loop inside findspan.m. Does anyone else get this?

Luigi Giaccari

### Luigi Giaccari (view profile)

Hello The Toolbox is not working for CATIA, any idea?

Evgeny Pr

Evgeny Pr

### Evgeny Pr (view profile)

Hello!
Where can I get C-implementation (mex-functions) of this toolbox? All links not working.

Thanks.

Michele Martinelli

### Michele Martinelli (view profile)

Hello everyone.
I'm trying to learn to use the NURBS toolbox.
I need it to interpolate freeform 2Dcurves obtained through a simulation, not for surfaces.

But I have some questions and doubts:
-are those files all what i need to generate NURBS?
- I expected to have the possibility to give a weight to each control point, but there isn't, or I didn't get how.

-i tried to generate a nurb with this inputs:

-d=3 "degree"

- c=[0 2 4 6 8; 0 6 2.5 6 6] "this is the control point matrix and I intended it as a two row matrix where the first one has the parametric coordinate and the second one the value of the point at that coordinate in a cartesian bi-dimensional space_Am I correct?"

- K= [0 0 0 1 2 3 3 3]; "Non uniform Knot vector".

-u= linspace(0,8); "parametric points where i want to evaluate the NURB"

I'm trying but it is not working. Would you be so kind to tell me what I m missing or I m doing wrong.
Then I see in the comments that there are comments about some functions that i don't have like nrbplot and nrbeval.
I am missing something.
Sorry for bothering but I really need to learn to use Nurbs with matlab.

Thanks.

--
Michele Martinelli

Michele Martinelli

### Michele Martinelli (view profile)

do I need spline toolbox to run this?
and is there any tutorial or something like that to learn how to use it?

THANKS

Ocean Yang

### Ocean Yang (view profile)

Great work!

However, I find a problem in computing the first derivatives for B-spline curves/surfaces with inner multiple-knots, e.g., [0 0 0 0.5 0.5 1 1 1].

When I evaluate the first derivatives at u=0.5, it seems wrong.

Eric Trautmann

### Eric Trautmann (view profile)

I found a copy of the NURBS toolbox (for 2006b) here:

http://webscripts.softpedia.com/script/Scientific-Engineering-Ruby/Mathematics/nurbs-33691.html

Does anyone know if there's a newer version of this?

Di Xiao

### Di Xiao (view profile)

Cannot find the original NURBS Toolbox

haidi

### haidi (view profile)

The link to the original NURBS library no longer works.

Could anyone could upload it again? Thanks

Jesper

### Jesper (view profile)

I've had the same problems with the weights and fixed it in this way:
In bspeval.m between line 45 and 46, I've inserted:
for i=0:d
N(i+1) = N(i+1)*c(4,tmp1+i);
end
N = N / sum(N);

This code applies the weights, but there is still a problem with nrbplot.m, but this is fixed by changing line 101 from
p = nrbeval(nurbs,linspace(0.0,1.0,subd));
to
[p, ggg] = nrbeval(nurbs,linspace(0.0,1.0,subd));

Where ggg is some variable, which isnt used afterwards.

Besides these small errors, this code is great. Maybe there are more error, but this works for me for now.

sheethal

### sheethal (view profile)

I am finding several problems with this code:
1. When we increase the weights, the curve should get pulled toward the control point. But, it is moving away from the curve and vice versa

2. democurve.m hangs and MATLAB crashes. Just running it without any modification does so.

Richard li

great job! Thanks

Martin Lo

This is great! Thank you so much!!! I just wasted 3 hours trying to compile the c files to mex files. The Matlab mex function is very buggy. Thanks so much!

Andre Lutz

Very good!

But there is a mistake in nrbcoons:

hold on
nrbplot(crv1,48);
nrbplot(crv2,48);
nrbplot(crv3,48);
nrbplot(crv4,48);

before the nrbcoons command in democoons, you will see that the coons surface does not match the curves.
Fix it with replacing line 82 in nrbcoons with:

t = nrb4surf(u1.coefs(:,1), u2.coefs(:,1), u1.coefs(:,end), u2.coefs(:,end));

Van Brackin

THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU

I was having a conniption when I couldn't get Mark Spinks' programs to run compiled.

Aslak Grinsted

I was thinking of doing just what you have done only last friday.. Excellent to find that it already has been done. thanks

##### MATLAB Release
MATLAB 7.3 (R2006b)