MATLAB 绘制有理Biezier曲线

本文通过Matlab代码示例介绍了二次Bezier曲线的绘制方法,并进一步展示了如何通过引入权重来实现有理Bezier曲线,权重的变化会影响曲线形状。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这里有一篇来自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的权值变小了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值