]> Creatis software - CreaPhase.git/blob - octave_packages/nurbs-1.3.6/nrbextrude.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / nurbs-1.3.6 / nrbextrude.m
1 function srf = nrbextrude(curve,vector)
2
3 %
4 % NRBEXTRUDE: Construct a NURBS surface by extruding a NURBS curve, or 
5 %  construct a NURBS volume by extruding a NURBS surface.
6
7 % Calling Sequence:
8
9 %   srf = nrbextrude(crv,vec);
10
11 % INPUT:
12
13 %   crv         : NURBS curve or surface to extrude, see nrbmak.
14
15 %   vec         : Vector along which the entity is extruded.
16 %
17 % OUTPUT: 
18
19 %   srf         : NURBS surface or volume constructed.
20
21 % Description:
22
23 %   Constructs either a NURBS surface by extruding a NURBS curve along a  
24 %   defined vector, or a NURBS volume by extruding a NURBS surface. In the 
25 %   first case, the NURBS curve forms the U direction of the surface edge, and
26 %   is extruded along the vector in the V direction. In the second case, the 
27 %   original surface forms the U and V direction of the volume, and is extruded
28 %   along the W direction.
29 %
30 % Examples:
31
32 %   Form a hollow cylinder by extruding a circle along the z-axis.
33 %
34 %   srf = nrbextrude(nrbcirc, [0,0,1]);
35 %
36 %    Copyright (C) 2000 Mark Spink
37 %    Copyright (C) 2010 Rafael Vazquez
38 %
39 %    This program is free software: you can redistribute it and/or modify
40 %    it under the terms of the GNU General Public License as published by
41 %    the Free Software Foundation, either version 2 of the License, or
42 %    (at your option) any later version.
43
44 %    This program is distributed in the hope that it will be useful,
45 %    but WITHOUT ANY WARRANTY; without even the implied warranty of
46 %    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
47 %    GNU General Public License for more details.
48 %
49 %    You should have received a copy of the GNU General Public License
50 %    along with this program.  If not, see <http://www.gnu.org/licenses/>.
51
52 if (nargin < 2)
53   error('Error too few input arguments!');
54 end
55
56 if (iscell (curve.knots))
57   if (numel (curve.knots) == 3)
58     error('Nurbs volumes cannot be extruded!');
59   end
60   for ii = 1:size(curve.coefs,3)
61     coefs(:,:,ii) = vectrans(vector) * squeeze (curve.coefs(:,:,ii));
62   end
63   coefs = cat(4,curve.coefs,coefs);
64   srf = nrbmak(coefs,{curve.knots{:}, [0 0 1 1]});
65 else
66   coefs = cat(3,curve.coefs,vectrans(vector)*curve.coefs);
67   srf = nrbmak(coefs,{curve.knots, [0 0 1 1]});
68 end
69
70 end
71
72 %!demo
73 %! crv = nrbtestcrv;
74 %! srf = nrbextrude(crv,[0 0 5]);
75 %! nrbplot(srf,[40 10]);
76 %! title('Extrusion of a test curve along the z-axis');
77 %! hold off
78 %
79 %!demo
80 %! crv1 = nrbcirc (1, [0 0], 0, pi/2);
81 %! crv2 = nrbcirc (2, [0 0], 0, pi/2);
82 %! srf  = nrbruled (crv1, crv2);
83 %! vol  = nrbextrude (srf, [0 0 1]);
84 %! nrbplot (vol, [30 10 10])
85 %! title ('Extrusion of the quarter of a ring')
86 %
87 %!demo
88 %! srf = nrbtestsrf;
89 %! vol = nrbextrude(srf, [0 0 10]);
90 %! nrbplot(vol,[20 20 20]);
91 %! title('Extrusion of a test surface along the z-axis');
92 %! hold off