Schreiben Sie ein MATLAB-Programm bez_draw, das die interaktive Eingabe
von Punkten für das Kontrollpolygon einer Bézier-Kurve ermöglicht
und die Kurve plottet.
function c = bez_draw(window)
% BEZ_DRAW : draw Bezier polygon
% c = bez_draw(window)
% interactive input of control points c(k,:)
% with left mouse button (quit with other key)
% in window = [xmin xmax ymin ymax]
if (~exist('window','var') | isempty(window))
window=[0 1 0 1];
end
hold on;
axis(window); axis square;
t = linspace(0,1);
c = [];
% add control points and draw Bezier curve
while 1
[x, y, button] = ginput(1);
if button == 1
c = [c; x,y];
cla;
p = bez_val(c,t);
plot(p(:,1),p(:,2),c(:,1),c(:,2),'bo-');
else
return
end;
end;
function p = bez_val(c,t)
% BEZ_VAL : evaluation of Bezier curves
% p = bez_val(c,t)
% points p(j,:) on a Bezier curve
% with control points c(k,:) at t(j)
n=size(c,1)-1;
b = zeros(length(t),2*n+1);
b(:,n+1) = 1;
for k=1:n
tk = repmat(t(:),1,2*n+1-k);
b = (1-tk).*b(:,2:end) + tk.*b(:,1:end-1);
end
p=b*c;
|
automatisch erstellt
am 8. 12. 2008 |