1 function curve = nrbcirc(radius,center,sang,eang)
3 % NRBCIRC: Construct a circular arc.
8 % crv = nrbcirc(radius)
9 % crv = nrbcirc(radius,center)
10 % crv = nrbcirc(radius,center,sang,eang)
14 % radius : Radius of the circle, default 1.0
16 % center : Center of the circle, default (0,0,0)
18 % sang : Start angle, default 0 radians (0 degrees)
20 % eang : End angle, default 2*pi radians (360 degrees)
24 % crv : NURBS curve for a circular arc.
28 % Constructs NURBS data structure for a circular arc in the x-y plane. If
29 % no rhs arguments are supplied a unit circle with center (0.0,0.0) is
32 % Angles are defined as positive in the anti-clockwise direction.
34 % Copyright (C) 2000 Mark Spink
36 % This program is free software: you can redistribute it and/or modify
37 % it under the terms of the GNU General Public License as published by
38 % the Free Software Foundation, either version 2 of the License, or
39 % (at your option) any later version.
41 % This program is distributed in the hope that it will be useful,
42 % but WITHOUT ANY WARRANTY; without even the implied warranty of
43 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
44 % GNU General Public License for more details.
46 % You should have received a copy of the GNU General Public License
47 % along with this program. If not, see <http://www.gnu.org/licenses/>.
62 sweep = eang - sang; % sweep angle of arc
68 narcs = 1; % number of arc segments
69 knots = [0 0 0 1 1 1];
70 elseif abs(sweep) <= pi
72 knots = [0 0 0 0.5 0.5 1 1 1];
73 elseif abs(sweep) <= 3*pi/2
75 knots = [0 0 0 1/3 1/3 2/3 2/3 1 1 1];
78 knots = [0 0 0 0.25 0.25 0.5 0.5 0.75 0.75 1 1 1];
81 dsweep = sweep/(2*narcs); % arc segment sweep angle/2
83 % determine middle control point and weight
86 y = radius*sin(dsweep);
89 % arc segment control points
90 ctrlpt = [ x wm*xm x; % w*x - coordinate
91 -y 0 y; % w*y - coordinate
92 0 0 0; % w*z - coordinate
93 1 wm 1]; % w - coordinate
95 % build up complete arc from rotated segments
96 coefs = zeros(4,2*narcs+1); % nurbs control points of arc
97 xx = vecrotz(sang + dsweep);
98 coefs(:,1:3) = xx*ctrlpt; % rotate to start angle
99 xx = vecrotz(2*dsweep);
102 coefs(:,m) = xx*coefs(:,m-2);
105 % vectrans arc if necessary
107 xx = vectrans(center);
111 curve = nrbmak(coefs,knots);
117 %! crv = nrbcirc(r,[],deg2rad(45),deg2rad(315));
123 %! title('NURBS construction of several 2D arcs.');