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
http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=312&objectType=file
The included files replace the following mex files with the m-file equivalent.
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.
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--');
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 ? ? :-]
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. *~*
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?
I've tried twice downloading/running, and ensured that no other implementation shadows any nurbs toolbox files... Any ideas?
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.
I downloaded the converted NURBS toolbox from this page.
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?"
-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.
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.
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.
17 Jul 2008
Richard li
great job! Thanks
29 Apr 2008
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!
03 Dec 2007
Andre Lutz
Very good!
But there is a mistake in nrbcoons:
If you add
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));
01 Jun 2007
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.
20 Mar 2007
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