1 function nrbctrlplot (nurbs)
3 % NRBCTRLPLOT: Plot a NURBS entity along with its control points.
11 % nurbs: NURBS curve or surface, see nrbmak.
15 % Plot the test curve and test surface with their control polygon and
16 % control net, respectively
18 % nrbctrlplot(nrbtestcrv)
19 % nrbctrlplot(nrbtestsrf)
25 % Copyright (C) 2011 Rafael Vazquez
27 % This program is free software: you can redistribute it and/or modify
28 % it under the terms of the GNU General Public License as published by
29 % the Free Software Foundation, either version 2 of the License, or
30 % (at your option) any later version.
32 % This program is distributed in the hope that it will be useful,
33 % but WITHOUT ANY WARRANTY; without even the implied warranty of
34 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35 % GNU General Public License for more details.
37 % You should have received a copy of the GNU General Public License
38 % along with this program. If not, see <http://www.gnu.org/licenses/>.
41 error ('nrbctrlplot: Need a NURBS to plot!');
52 if (iscell (nurbs.knots))
53 if (size (nurbs.knots,2) == 3)
54 error ('nrbctrlplot: not implemented for NURBS volumes');
55 elseif (size (nurbs.knots,2) == 2) % plot a NURBS surface
58 nrbplot (nurbs, [nsub nsub], 'light', light, 'colormap', cmap);
61 % And plot the control net
62 for ii = 1:size (nurbs.coefs, 2)
63 coefs = reshape (nurbs.coefs(1:3,ii,:), 3, []);
64 weights = reshape (nurbs.coefs(4,ii,:), 1, []);
65 plot3 (coefs(1,:)./weights, coefs(2,:)./weights, coefs(3,:)./weights,'k--')
66 plot3 (coefs(1,:)./weights, coefs(2,:)./weights, coefs(3,:)./weights,'r.','MarkerSize',20)
68 for jj = 1:size (nurbs.coefs, 3)
69 coefs = reshape (nurbs.coefs(1:3,:,jj), 3, []);
70 weights = reshape (nurbs.coefs(4,:,jj), 1, []);
71 plot3 (coefs(1,:)./weights, coefs(2,:)./weights, coefs(3,:)./weights,'k--')
72 plot3 (coefs(1,:)./weights, coefs(2,:)./weights, coefs(3,:)./weights,'r.','MarkerSize',20)
75 else % plot a NURBS curve
77 nrbplot (nurbs, nsub);
80 % And plot the control polygon
81 coefs = nurbs.coefs(1:3,:);
82 weights = nurbs.coefs(4,:);
83 plot3 (coefs(1,:)./weights, coefs(2,:)./weights, coefs(3,:)./weights,'k--')
84 plot3 (coefs(1,:)./weights, coefs(2,:)./weights, coefs(3,:)./weights,'r.','MarkerSize',20)
96 %! title('Test curve')
102 %! title('Test surface')