Mercurial > forge
annotate extra/nurbs/inst/nrbcoons.m @ 12667:1411b4cf3c81 octave-forge
Check that the curves formed a closed surface
author | rafavzqz |
---|---|
date | Tue, 28 Jul 2015 10:24:42 +0000 |
parents | 37d08939bb7b |
children |
rev | line source |
---|---|
5552 | 1 function srf = nrbcoons(u1, u2, v1, v2) |
2 % | |
3 % NRBCOONS: Construction of a Coons patch. | |
4 % | |
5 % Calling Sequence: | |
6 % | |
7 % srf = nrbcoons(ucrv1, ucrv2, vcrv1, vcrv2) | |
8 % | |
6910 | 9 % INPUT: |
5552 | 10 % |
6958 | 11 % ucrv1 : NURBS curve defining the bottom U direction boundary of |
5552 | 12 % the constructed NURBS surface. |
13 % | |
14 % ucrv2 : NURBS curve defining the top U direction boundary of | |
15 % the constructed NURBS surface. | |
16 % | |
17 % vcrv1 : NURBS curve defining the bottom V direction boundary of | |
18 % the constructed NURBS surface. | |
19 % | |
20 % vcrv2 : NURBS curve defining the top V direction boundary of | |
21 % the constructed NURBS surface. | |
6910 | 22 % |
23 % OUTPUT: | |
5552 | 24 % |
25 % srf : Coons NURBS surface patch. | |
26 % | |
27 % Description: | |
28 % | |
29 % Construction of a bilinearly blended Coons surface patch from four NURBS | |
30 % curves that define the boundary. | |
31 % | |
32 % The orientation of the four NURBS boundary curves. | |
33 % | |
34 % ^ V direction | |
35 % | | |
36 % | ucrv2 | |
37 % ------->-------- | |
38 % | | | |
39 % | | | |
40 % vcrv1 ^ Surface ^ vcrv2 | |
41 % | | | |
42 % | | | |
43 % ------->-----------> U direction | |
44 % ucrv1 | |
45 % | |
46 % | |
47 % Examples: | |
48 % | |
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]); | |
54 % | |
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]); | |
59 % | |
60 % pnts= [ 0.0 0.0 0.0 0.0; | |
61 % 0.0 3.0 8.0 10.0; | |
62 % 2.0 0.0 5.0 3.0]; | |
63 % crv3 = nrbmak(pnts, [0 0 0 0.5 1 1 1]); | |
64 % | |
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]); | |
69 % | |
70 % srf = nrbcoons(crv1, crv2, crv3, crv4); | |
71 % nrbplot(srf,[20 20],220,45); | |
6910 | 72 % |
7919
27876b20006b
Spink's version of nrbcoons, the bug was in nrb4surf
rafavzqz
parents:
6958
diff
changeset
|
73 % Copyright (C) 2000 Mark Spink |
6910 | 74 % |
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 | |
11634 | 77 % the Free Software Foundation, either version 3 of the License, or |
6910 | 78 % (at your option) any later version. |
5552 | 79 |
6910 | 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. | |
84 % | |
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/>. | |
5552 | 87 |
88 if nargin ~= 4 | |
89 error('Incorrect number of input arguments'); | |
90 end | |
91 | |
12667 | 92 if (max (abs (nrbeval (u1, u1.knots(1)) - nrbeval (v1, v1.knots(1)))) > 1e-10 || ... |
93 max (abs (nrbeval (u1, u1.knots(end)) - nrbeval (v2, v2.knots(1)))) > 1e-10 || ... | |
94 max (abs (nrbeval (u2, u2.knots(1)) - nrbeval (v1, v1.knots(end)))) > 1e-10 || ... | |
95 max (abs (nrbeval (u2, u2.knots(end)) - nrbeval (v2, v2.knots(end)))) > 1e-10) | |
96 error ('The four curves do not define a closed boundary') | |
97 end | |
98 | |
99 | |
100 | |
5552 | 101 r1 = nrbruled(u1, u2); |
102 r2 = nrbtransp(nrbruled(v1, v2)); | |
7919
27876b20006b
Spink's version of nrbcoons, the bug was in nrb4surf
rafavzqz
parents:
6958
diff
changeset
|
103 t = nrb4surf(u1.coefs(:,1), u1.coefs(:,end), u2.coefs(:,1), u2.coefs(:,end)); |
5552 | 104 |
105 % raise all surfaces to a common degree | |
106 du = max([r1.order(1), r2.order(1), t.order(1)]); | |
107 dv = max([r1.order(2), r2.order(2), t.order(2)]); | |
108 r1 = nrbdegelev(r1, [du - r1.order(1), dv - r1.order(2)]); | |
109 r2 = nrbdegelev(r2, [du - r2.order(1), dv - r2.order(2)]); | |
110 t = nrbdegelev(t, [du - t.order(1), dv - t.order(2)]); | |
111 | |
112 % merge the knot vectors, to obtain a common knot vector | |
113 | |
114 % U knots | |
115 k1 = r1.knots{1}; | |
116 k2 = r2.knots{1}; | |
117 k3 = t.knots{1}; | |
118 k = unique([k1 k2 k3]); | |
119 n = length(k); | |
120 kua = []; | |
121 kub = []; | |
122 kuc = []; | |
123 for i = 1:n | |
124 i1 = length(find(k1 == k(i))); | |
125 i2 = length(find(k2 == k(i))); | |
126 i3 = length(find(k3 == k(i))); | |
127 m = max([i1, i2, i3]); | |
128 kua = [kua k(i)*ones(1,m-i1)]; | |
129 kub = [kub k(i)*ones(1,m-i2)]; | |
130 kuc = [kuc k(i)*ones(1,m-i3)]; | |
131 end | |
132 | |
133 % V knots | |
134 k1 = r1.knots{2}; | |
135 k2 = r2.knots{2}; | |
136 k3 = t.knots{2}; | |
137 k = unique([k1 k2 k3]); | |
138 n = length(k); | |
139 kva = []; | |
140 kvb = []; | |
141 kvc = []; | |
142 for i = 1:n | |
143 i1 = length(find(k1 == k(i))); | |
144 i2 = length(find(k2 == k(i))); | |
145 i3 = length(find(k3 == k(i))); | |
146 m = max([i1, i2, i3]); | |
147 kva = [kva k(i)*ones(1,m-i1)]; | |
148 kvb = [kvb k(i)*ones(1,m-i2)]; | |
149 kvc = [kvc k(i)*ones(1,m-i3)]; | |
150 end | |
151 | |
152 r1 = nrbkntins(r1, {kua, kva}); | |
153 r2 = nrbkntins(r2, {kub, kvb}); | |
154 t = nrbkntins(t, {kuc, kvc}); | |
155 | |
156 % combine coefficient to construct Coons surface | |
157 coefs(1,:,:) = r1.coefs(1,:,:) + r2.coefs(1,:,:) - t.coefs(1,:,:); | |
158 coefs(2,:,:) = r1.coefs(2,:,:) + r2.coefs(2,:,:) - t.coefs(2,:,:); | |
159 coefs(3,:,:) = r1.coefs(3,:,:) + r2.coefs(3,:,:) - t.coefs(3,:,:); | |
160 coefs(4,:,:) = r1.coefs(4,:,:) + r2.coefs(4,:,:) - t.coefs(4,:,:); | |
161 srf = nrbmak(coefs, r1.knots); | |
162 | |
6910 | 163 end |
164 | |
165 %!demo | |
166 %! pnts = [ 0.0 3.0 4.5 6.5 8.0 10.0; | |
167 %! 0.0 0.0 0.0 0.0 0.0 0.0; | |
168 %! 2.0 2.0 7.0 4.0 7.0 9.0]; | |
169 %! crv1 = nrbmak(pnts, [0 0 0 1/3 0.5 2/3 1 1 1]); | |
170 %! | |
171 %! pnts= [ 0.0 3.0 5.0 8.0 10.0; | |
172 %! 10.0 10.0 10.0 10.0 10.0; | |
173 %! 3.0 5.0 8.0 6.0 10.0]; | |
174 %! crv2 = nrbmak(pnts, [0 0 0 1/3 2/3 1 1 1]); | |
175 %! | |
176 %! pnts= [ 0.0 0.0 0.0 0.0; | |
177 %! 0.0 3.0 8.0 10.0; | |
178 %! 2.0 0.0 5.0 3.0]; | |
179 %! crv3 = nrbmak(pnts, [0 0 0 0.5 1 1 1]); | |
180 %! | |
181 %! pnts= [ 10.0 10.0 10.0 10.0 10.0; | |
182 %! 0.0 3.0 5.0 8.0 10.0; | |
183 %! 9.0 7.0 7.0 10.0 10.0]; | |
184 %! crv4 = nrbmak(pnts, [0 0 0 0.25 0.75 1 1 1]); | |
185 %! | |
186 %! srf = nrbcoons(crv1, crv2, crv3, crv4); | |
187 %! | |
188 %! nrbplot(srf,[20 20]); | |
189 %! title('Construction of a bilinearly blended Coons surface.'); | |
7919
27876b20006b
Spink's version of nrbcoons, the bug was in nrb4surf
rafavzqz
parents:
6958
diff
changeset
|
190 %! hold off |