1 function nurbs = nrbtform(nurbs,tmat)
3 % NRBTFORM: Apply transformation matrix to the NURBS.
7 % tnurbs = nrbtform(nurbs,tmatrix);
11 % nurbs : NURBS data structure (see nrbmak for details).
13 % tmatrix : Transformation matrix, a matrix of size (4,4) defining
14 % a single or multiple transformations.
18 % tnurbs : The return transformed NURBS data structure.
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.
30 % Rotate a square by 45 degrees about the z axis.
32 % rsqr = nrbtform(nrbrect(), vecrotz(deg2rad(45)));
33 % nrbplot(rsqr, 1000);
37 % vecscale, vectrans, vecrotx, vecroty, vecrotz
39 % Copyright (C) 2000 Mark Spink
40 % Copyright (C) 2010 Rafael Vazquez
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.
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.
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/>.
56 error('Not enough input arguments!');
59 if iscell(nurbs.knots)
60 if size(nurbs.knots,2) == 2
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
66 [dim,nu,nv,nw] = size(nurbs.coefs);
67 nurbs.coefs = reshape(tmat*reshape(nurbs.coefs,dim,nu*nv*nw),[dim nu nv nw]);
71 nurbs.coefs = tmat*nurbs.coefs;
77 %! xx = vectrans([2.0 1.0])*vecroty(pi/8)*vecrotx(pi/4)*vecscale([1.0 2.0]);
78 %! c0 = nrbtform(nrbcirc, xx);
81 %! title('Construction of an ellipse by transforming a unit circle.');