]> Creatis software - CreaPhase.git/blob - octave_packages/nurbs-1.3.6/nrbtform.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / nurbs-1.3.6 / nrbtform.m
1 function nurbs = nrbtform(nurbs,tmat)
2
3 % NRBTFORM: Apply transformation matrix to the NURBS.
4
5 % Calling Sequence:
6
7 %   tnurbs = nrbtform(nurbs,tmatrix);
8
9 % INPUT:
10
11 %   nurbs       : NURBS data structure (see nrbmak for details).
12
13 %   tmatrix     : Transformation matrix, a matrix of size (4,4) defining
14 %                 a single or multiple transformations.
15 %
16 % OUTPUT:
17 %
18 %   tnurbs      : The return transformed NURBS data structure.
19
20 % Description:
21
22 %   The NURBS is transform as defined a transformation matrix of size (4,4),
23 %   such as a rotation, translation or change in scale. The transformation
24 %   matrix can define a single transformation or multiple series of
25 %   transformations. The matrix can be simple constructed by the functions
26 %   vecscale, vectrans, vecrotx, vecroty, and vecrotz.
27 %     
28 % Examples:
29
30 %   Rotate a square by 45 degrees about the z axis.
31 %
32 %   rsqr = nrbtform(nrbrect(), vecrotz(deg2rad(45)));
33 %   nrbplot(rsqr, 1000);
34
35 % See also:
36
37 %   vecscale, vectrans, vecrotx, vecroty, vecrotz
38 %
39 %    Copyright (C) 2000 Mark Spink
40 %    Copyright (C) 2010 Rafael Vazquez
41 %
42 %    This program is free software: you can redistribute it and/or modify
43 %    it under the terms of the GNU General Public License as published by
44 %    the Free Software Foundation, either version 2 of the License, or
45 %    (at your option) any later version.
46
47 %    This program is distributed in the hope that it will be useful,
48 %    but WITHOUT ANY WARRANTY; without even the implied warranty of
49 %    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
50 %    GNU General Public License for more details.
51 %
52 %    You should have received a copy of the GNU General Public License
53 %    along with this program.  If not, see <http://www.gnu.org/licenses/>.
54
55 if nargin < 2
56   error('Not enough input arguments!');
57 end;
58
59 if iscell(nurbs.knots)
60  if size(nurbs.knots,2) == 2
61   % NURBS is a surface
62   [dim,nu,nv] = size(nurbs.coefs);
63   nurbs.coefs = reshape(tmat*reshape(nurbs.coefs,dim,nu*nv),[dim nu nv]);
64  elseif size(nurbs.knots,2) == 3
65   % NURBS is a volume
66   [dim,nu,nv,nw] = size(nurbs.coefs);
67   nurbs.coefs = reshape(tmat*reshape(nurbs.coefs,dim,nu*nv*nw),[dim nu nv nw]);
68  end
69 else
70   % NURBS is a curve
71   nurbs.coefs = tmat*nurbs.coefs;
72 end
73
74 end
75
76 %!demo
77 %! xx = vectrans([2.0 1.0])*vecroty(pi/8)*vecrotx(pi/4)*vecscale([1.0 2.0]);
78 %! c0 = nrbtform(nrbcirc, xx);
79 %! nrbplot(c0,50);
80 %! grid on
81 %! title('Construction of an ellipse by transforming a unit circle.');
82 %! hold off