1 function srf = nrbcoons(u1, u2, v1, v2)
3 % NRBCOONS: Construction of a Coons patch.
7 % srf = nrbcoons(ucrv1, ucrv2, vcrv1, vcrv2)
11 % ucrv1 : NURBS curve defining the bottom U direction boundary of
12 % the constructed NURBS surface.
14 % ucrv2 : NURBS curve defining the top U direction boundary of
15 % the constructed NURBS surface.
17 % vcrv1 : NURBS curve defining the bottom V direction boundary of
18 % the constructed NURBS surface.
20 % vcrv2 : NURBS curve defining the top V direction boundary of
21 % the constructed NURBS surface.
25 % srf : Coons NURBS surface patch.
29 % Construction of a bilinearly blended Coons surface patch from four NURBS
30 % curves that define the boundary.
32 % The orientation of the four NURBS boundary curves.
40 % vcrv1 ^ Surface ^ vcrv2
43 % ------->-----------> U direction
49 % // Define four NURBS curves and construct a Coons surface patch.
50 % pnts = [ 0.0 3.0 4.5 6.5 8.0 10.0;
51 % 0.0 0.0 0.0 0.0 0.0 0.0;
52 % 2.0 2.0 7.0 4.0 7.0 9.0];
53 % crv1 = nrbmak(pnts, [0 0 0 1/3 0.5 2/3 1 1 1]);
55 % pnts= [ 0.0 3.0 5.0 8.0 10.0;
56 % 10.0 10.0 10.0 10.0 10.0;
57 % 3.0 5.0 8.0 6.0 10.0];
58 % crv2 = nrbmak(pnts, [0 0 0 1/3 2/3 1 1 1]);
60 % pnts= [ 0.0 0.0 0.0 0.0;
63 % crv3 = nrbmak(pnts, [0 0 0 0.5 1 1 1]);
65 % pnts= [ 10.0 10.0 10.0 10.0 10.0;
66 % 0.0 3.0 5.0 8.0 10.0;
67 % 9.0 7.0 7.0 10.0 10.0];
68 % crv4 = nrbmak(pnts, [0 0 0 0.25 0.75 1 1 1]);
70 % srf = nrbcoons(crv1, crv2, crv3, crv4);
71 % nrbplot(srf,[20 20],220,45);
73 % Copyright (C) 2000 Mark Spink
75 % This program is free software: you can redistribute it and/or modify
76 % it under the terms of the GNU General Public License as published by
77 % the Free Software Foundation, either version 2 of the License, or
78 % (at your option) any later version.
80 % This program is distributed in the hope that it will be useful,
81 % but WITHOUT ANY WARRANTY; without even the implied warranty of
82 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
83 % GNU General Public License for more details.
85 % You should have received a copy of the GNU General Public License
86 % along with this program. If not, see <http://www.gnu.org/licenses/>.
89 error('Incorrect number of input arguments');
92 r1 = nrbruled(u1, u2);
93 r2 = nrbtransp(nrbruled(v1, v2));
94 t = nrb4surf(u1.coefs(:,1), u1.coefs(:,end), u2.coefs(:,1), u2.coefs(:,end));
96 % raise all surfaces to a common degree
97 du = max([r1.order(1), r2.order(1), t.order(1)]);
98 dv = max([r1.order(2), r2.order(2), t.order(2)]);
99 r1 = nrbdegelev(r1, [du - r1.order(1), dv - r1.order(2)]);
100 r2 = nrbdegelev(r2, [du - r2.order(1), dv - r2.order(2)]);
101 t = nrbdegelev(t, [du - t.order(1), dv - t.order(2)]);
103 % merge the knot vectors, to obtain a common knot vector
109 k = unique([k1 k2 k3]);
115 i1 = length(find(k1 == k(i)));
116 i2 = length(find(k2 == k(i)));
117 i3 = length(find(k3 == k(i)));
118 m = max([i1, i2, i3]);
119 kua = [kua k(i)*ones(1,m-i1)];
120 kub = [kub k(i)*ones(1,m-i2)];
121 kuc = [kuc k(i)*ones(1,m-i3)];
128 k = unique([k1 k2 k3]);
134 i1 = length(find(k1 == k(i)));
135 i2 = length(find(k2 == k(i)));
136 i3 = length(find(k3 == k(i)));
137 m = max([i1, i2, i3]);
138 kva = [kva k(i)*ones(1,m-i1)];
139 kvb = [kvb k(i)*ones(1,m-i2)];
140 kvc = [kvc k(i)*ones(1,m-i3)];
143 r1 = nrbkntins(r1, {kua, kva});
144 r2 = nrbkntins(r2, {kub, kvb});
145 t = nrbkntins(t, {kuc, kvc});
147 % combine coefficient to construct Coons surface
148 coefs(1,:,:) = r1.coefs(1,:,:) + r2.coefs(1,:,:) - t.coefs(1,:,:);
149 coefs(2,:,:) = r1.coefs(2,:,:) + r2.coefs(2,:,:) - t.coefs(2,:,:);
150 coefs(3,:,:) = r1.coefs(3,:,:) + r2.coefs(3,:,:) - t.coefs(3,:,:);
151 coefs(4,:,:) = r1.coefs(4,:,:) + r2.coefs(4,:,:) - t.coefs(4,:,:);
152 srf = nrbmak(coefs, r1.knots);
157 %! pnts = [ 0.0 3.0 4.5 6.5 8.0 10.0;
158 %! 0.0 0.0 0.0 0.0 0.0 0.0;
159 %! 2.0 2.0 7.0 4.0 7.0 9.0];
160 %! crv1 = nrbmak(pnts, [0 0 0 1/3 0.5 2/3 1 1 1]);
162 %! pnts= [ 0.0 3.0 5.0 8.0 10.0;
163 %! 10.0 10.0 10.0 10.0 10.0;
164 %! 3.0 5.0 8.0 6.0 10.0];
165 %! crv2 = nrbmak(pnts, [0 0 0 1/3 2/3 1 1 1]);
167 %! pnts= [ 0.0 0.0 0.0 0.0;
170 %! crv3 = nrbmak(pnts, [0 0 0 0.5 1 1 1]);
172 %! pnts= [ 10.0 10.0 10.0 10.0 10.0;
173 %! 0.0 3.0 5.0 8.0 10.0;
174 %! 9.0 7.0 7.0 10.0 10.0];
175 %! crv4 = nrbmak(pnts, [0 0 0 0.25 0.75 1 1 1]);
177 %! srf = nrbcoons(crv1, crv2, crv3, crv4);
179 %! nrbplot(srf,[20 20]);
180 %! title('Construction of a bilinearly blended Coons surface.');