这里有一篇来自tue的课程资料,叫做A gentle introduction to rational Bezier curves and NURBS,具体的文档我已经放在我的下载里了,因为翻译的工作量过大,我就不翻译了,应该看得懂的
下面主要是把文章中的代码摘出来给大家演示一下
Quadratic Bezier curve(二次Bezier曲线)
% Initialise
clear all;
close all;
clc;
% Partition interval [0,1] to get a good resolution for plotting
t = 0:.025:1;
% Define the quadratic Bernstein polynomials
Bernstein = [ (1-t).^2; 2*t.*(1-t); t.^2 ];
% Define three control points (X,Y)
P = [1 0;
3,4;
5,1];
% Beziers for the X and Y coordinates
DataX = Bernstein(1,:) * P(1,1) + Bernstein(2,:) * P(2,1) + Bernstein(3,:) * P(3,1);
DataY = Bernstein(1,:) * P(1,2) + Bernstein(2,:) * P(2,2) + Bernstein(3,:) * P(3,2);
% Initialise figure
figure
axis equal
hold on
% Plot control polygon
plot( P(:,1), P(:,2), 'k.--', 'LineWidth', 1, 'MarkerSize', 30 );
% Plot Bezier curve
plot( DataX, DataY, 'Color', [255/255,127/255,42/255], 'LineWidth', 2 );
% Add labels for control points P i
for i=1:length(P)
text( P(i,1), P(i,2), [' P ', num2str(i) ], 'FontSize', 16, 'Color',...
[0,129/255,195/255] );
end
显示效果如下图
对于有理Bezier曲线,给附上一定的权值
将上面的第 16-18 用下面的5行语句替换得到有理Bezier曲线
Weights = [1, .75, 1];
% Rational Beziers for the X and Y coordinates
DataX = ( Weights(1)*Bernstein(1,:) * P(1,1) + Weights(2)*Bernstein(2,:) * P(2,1) +...
Weights(3)*Bernstein(3,:) * P(3,1) ) ./ ( Weights(1)*Bernstein(1,:) + Weights...
(2)*Bernstein(2,:) + Weights(3)*Bernstein(3,:) );
DataY = ( Weights(1)*Bernstein(1,:) * P(1,2) + Weights(2)*Bernstein(2,:) * P(2,2) +...
Weights(3)*Bernstein(3,:) * P(3,2) ) ./ ( Weights(1)*Bernstein(1,:) + Weights...
(2)*Bernstein(2,:) + Weights(3)*Bernstein(3,:) );
效果为
可以看得出来曲线距离P2点比之前更加远了一些,就是因为P2的权值变小了