]> Creatis software - CreaPhase.git/blob - octave_packages/nurbs-1.3.6/nrbruled.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / nurbs-1.3.6 / nrbruled.m
1 function srf = nrbruled (crv1, crv2)
2
3 % NRBRULED: Construct a ruled surface between two NURBS curves.
4
5 % Calling Sequence:
6
7 %   srf = nrbruled(crv1, crv2)
8
9 % INPUT:
10
11 %   crv1        : First NURBS curve, see nrbmak.
12
13 %   crv2        : Second NURBS curve, see nrbmak.
14 %
15 % OUTPUT:
16
17 %   srf         : Ruled NURBS surface.
18
19 % Description:
20
21 %   Constructs a ruled surface between two NURBS curves. The ruled surface is
22 %   ruled along the V direction.
23
24 % Examples:
25
26 %   Construct a ruled surface between a semicircle and a straight line.
27
28 %   cir = nrbcirc(1,[0 0 0],0,pi);
29 %   line = nrbline([-1 0.5 1],[1 0.5 1]);
30 %   srf = nrbruled(cir,line);
31 %   nrbplot(srf,[20 20]);
32 %
33 %    Copyright (C) 2000 Mark Spink
34 %
35 %    This program is free software: you can redistribute it and/or modify
36 %    it under the terms of the GNU General Public License as published by
37 %    the Free Software Foundation, either version 2 of the License, or
38 %    (at your option) any later version.
39
40 %    This program is distributed in the hope that it will be useful,
41 %    but WITHOUT ANY WARRANTY; without even the implied warranty of
42 %    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
43 %    GNU General Public License for more details.
44 %
45 %    You should have received a copy of the GNU General Public License
46 %    along with this program.  If not, see <http://www.gnu.org/licenses/>.
47
48 if (iscell(crv1.knots) || iscell(crv2.knots))
49   error ('Both NURBS must be curves');
50 end
51
52 % ensure both curves have a common degree
53 d = max ([crv1.order, crv2.order]);
54 crv1 = nrbdegelev (crv1, d - crv1.order);
55 crv2 = nrbdegelev (crv2, d - crv2.order);
56
57 % merge the knot vectors, to obtain a common knot vector
58 k1 = crv1.knots;
59 k2 = crv2.knots;
60 ku = unique ([k1 k2]);
61 n = length (ku);
62 ka = [];
63 kb = [];
64 for i = 1:n
65   i1 = length (find (k1 == ku(i)));
66   i2 = length (find (k2 == ku(i)));
67   m = max (i1, i2);
68   ka = [ka ku(i)*ones(1,m-i1)];
69   kb = [kb ku(i)*ones(1,m-i2)];
70 end
71 crv1 = nrbkntins (crv1, ka);
72 crv2 = nrbkntins (crv2, kb);
73
74 coefs(:,:,1) = crv1.coefs;
75 coefs(:,:,2) = crv2.coefs;
76 srf = nrbmak (coefs, {crv1.knots, [0 0 1 1]});
77
78 end
79
80 %!demo
81 %! pnts = [0.5 1.5 4.5 3.0 7.5 6.0 8.5;
82 %!         3.0 5.5 5.5 1.5 1.5 4.0 4.5;
83 %!         0.0 0.0 0.0 0.0 0.0 0.0 0.0];
84 %! crv1 = nrbmak (pnts,[0 0 0 1/4 1/2 3/4 3/4 1 1 1]);
85 %! crv2 = nrbtform (nrbcirc (4,[4.5;0],pi,0.0),vectrans([0.0 4.0 -4.0]));
86 %! srf = nrbruled (crv1,crv2);
87 %! nrbplot (srf,[40 20]);
88 %! title ('Ruled surface construction from two NURBS curves.');
89 %! hold off