Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

% Initialise

clear all;
close all;
clc;
% Partition interval [0,1] to get a good resolution for plotting
t = 0:.025:1; 8
% Define the quadratic Bernstein polynomials
Bernstein = [ (1-t).2; 2*t.*(1-t); t.2 ];
% Define three control points (X,Y)
P = [1 0; 13 3,4; 14 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 31 for i=1:length(P)
text( P(i,1), P(i,2), [' P ', num2str(i) ], 'FontSize', 16, 'Color',
[0,129/255,195/255] ); 33 end

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,:) );

You might also like