]> Creatis software - CreaPhase.git/blob - octave_packages/nurbs-1.3.6/nrbreverse.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / nurbs-1.3.6 / nrbreverse.m
1 function rnrb = nrbreverse(nrb)
2 %
3 % NRBREVERSE: Reverse the evaluation direction of a NURBS curve or surface.
4
5 % Calling Sequence:
6
7 %   rnrb = nrbreverse(nrb);
8
9 % INPUT:
10
11 %   nrb         : NURBS data structure, see nrbmak.
12 %
13 % OUTPUT:
14
15 %   rnrb        : Reversed NURBS.
16
17 % Description:
18
19 %   Utility function to reverse the evaluation direction of a NURBS
20 %   curve or surface.
21 %
22 %    Copyright (C) 2000 Mark Spink
23 %
24 %    This program is free software: you can redistribute it and/or modify
25 %    it under the terms of the GNU General Public License as published by
26 %    the Free Software Foundation, either version 2 of the License, or
27 %    (at your option) any later version.
28
29 %    This program is distributed in the hope that it will be useful,
30 %    but WITHOUT ANY WARRANTY; without even the implied warranty of
31 %    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
32 %    GNU General Public License for more details.
33 %
34 %    You should have received a copy of the GNU General Public License
35 %    along with this program.  If not, see <http://www.gnu.org/licenses/>.
36
37 if nargin ~= 1
38   error('Incorrect number of input arguments');
39 end
40
41 if iscell(nrb.knots)
42  if size(nrb.knots,2) == 3
43   error('The function nrbreverse is not yet ready for volumes')
44  else
45   % reverse a NURBS surface
46   coefs = nrb.coefs(:,:,end:-1:1);
47   rnrb = nrbmak(coefs(:,end:-1:1,:), {1.0-fliplr(nrb.knots{1}),...
48                 1.0-fliplr(nrb.knots{2})});
49  end
50
51 else
52
53   % reverse a NURBS curve
54   rnrb = nrbmak(fliplr(nrb.coefs), 1.0-fliplr(nrb.knots));
55
56 end
57
58 end
59
60 %!demo
61 %! pnts = [0.5 1.5 3.0 7.5 8.5;
62 %!         3.0 5.5 1.5 4.0 4.5;
63 %!         0.0 0.0 0.0 0.0 0.0];
64 %! crv1 = nrbmak(pnts,[0 0 0 1/2 3/4 1 1 1]);
65 %! crv2 = nrbreverse(crv1);
66 %! fprintf('Knots of the original curve\n')
67 %! disp(crv1.knots)
68 %! fprintf('Knots of the reversed curve\n')
69 %! disp(crv2.knots)
70 %! fprintf('Control points of the original curve\n')
71 %! disp(crv1.coefs(1:2,:))
72 %! fprintf('Control points of the reversed curve\n')
73 %! disp(crv2.coefs(1:2,:))
74 %! nrbplot(crv1,100)
75 %! hold on
76 %! nrbplot(crv2,100)
77 %! title('The curve and its reverse are the same')
78 %! hold off