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

clc

clear all
close all
B = [1,1;2,3;4,3;3,1]; % Vertices of Polygon
[r,s] = size(B);
n = r-1; % n + 1 = Number of Polygon Vertices
np = 20; % Number of equidistant points on Bezier Curve
t = linspace(0,1,np); %Value of parameter ‘t’ for all the points on Curve
for k = 1:n
figure(1); plot([B(k,1),B(k+1,1)],[B(k,2),B(k+1,2)],'r','LineWidth',2)
hold on% To hold figure handle on same figure
end
for j = 1:np
P =[0,0];
for i = 0:n
J(i+1) = factorial(n)/(factorial(i)*(factorial(n-i)))*t(j)^i*(1-t(j))^(n-i);
P = P + B(i+1,:)*J(i+1);
end
Q (j,:) = P;
end
for l = 1:np-1
figure(1); plot([Q(l,1),Q(l+1,1)],[Q(l,2),Q(l+1,2)],'--b','LineWidth',2)
hold on% To hold figure handle on same figure
end

You might also like