Documente Academic
Documente Profesional
Documente Cultură
EQT 535
COMPUTER AIDED GEOMETRIC DESIGN FOR SURFACE MODELLING
(ASSIGNMENT 1)
Assume p0, p1, p2, and p3 are the points need to be interpolated using either Aitken or
Lagrange with value t0, t1, t2, and t3 are 0, 1/3, 2/3 and 1 respectively. Explain how we can
generate the same parametric curve using cubic Bezier with control points b0, b1, b2, and b3.
Then, generate both curves in MATLAB with example of your own.
Solution:
𝑥(𝑡)
ℙ(𝑡) = ℙ0 ℒ0𝑛 + ℙ0 ℒ1𝑛 + ⋯ + ℙ0 ℒ𝑛𝑛 𝑤ℎ𝑒𝑟𝑒 ℙ(𝑡) = {𝑦(𝑡) }
1, 𝑖𝑓 𝑗 = 1
Where; ℒ𝑖𝑛 (𝑡𝑗 ) = {
0 , 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
Thus;
𝑛
(𝑡 − 𝑡𝑗 )
ℒ𝑖𝑛 (𝑡) = ∏ , 𝑗≠𝑖
(𝑡𝑖 − 𝑡𝑗 )
𝑗=0
(𝑡 − 𝑡1 )(𝑡 − 𝑡2 )(𝑡 − 𝑡3 )
ℒ03 (𝑡) =
(𝑡0 − 𝑡1 )(𝑡0 − 𝑡2 )(𝑡0 − 𝑡3 )
1 2
(𝑡 − 3) (𝑡 − 3) (𝑡 − 1)
= = −𝟒. 𝟓𝒕𝟑 + 𝟗𝒕𝟐 − 𝟓. 𝟓𝒕 + 𝟏
1 2
(0 − 3) (0 − 3) (0 − 1)
(𝑡 − 𝑡0 )(𝑡 − 𝑡2 )(𝑡 − 𝑡3 )
ℒ13 (𝑡) =
(𝑡1 − 𝑡0 )(𝑡1 − 𝑡2 )(𝑡0 − 𝑡3 )
2
(𝑡 − 0) (𝑡 − ) (𝑡 − 1)
= 3 = 𝟏𝟑. 𝟓𝒕𝟑 − 𝟐𝟐. 𝟓𝒕𝟐 + 𝟗𝒕
1 1 2 1
(3 − 0) (3 − 3) (3 − 1)
(𝑡 − 𝑡0 )(𝑡 − 𝑡1 )(𝑡 − 𝑡3 )
ℒ23 (𝑡) =
(𝑡2 − 𝑡0 )(𝑡2 − 𝑡1 )(𝑡2 − 𝑡3 )
1
(𝑡 − 0) (𝑡 − ) (𝑡 − 1)
= 3 = −𝟏𝟑. 𝟓𝒕𝟑 + 𝟏𝟖𝒕𝟐 − 𝟒. 𝟓𝒕
2 2 1 2
(3 − 0) (3 − 3) (3 − 1)
(𝑡 − 𝑡0 )(𝑡 − 𝑡1 )(𝑡 − 𝑡2 )
ℒ33 (𝑡) =
(𝑡3 − 𝑡0 )(𝑡3 − 𝑡1 )(𝑡3 − 𝑡2 )
1 2
(𝑡 − 0) (𝑡 − ) (𝑡 − )
= 3 3 = 𝟒. 𝟓𝒕𝟑 − 𝟒𝟓𝒕𝟐 + 𝒕
1 2
(1 − 0) (1 − ) (1 − )
3 3
𝑥(𝑡)
𝕡(𝑡) = {𝑦(𝑡) } = {𝑥𝑦0} ℒ03 (𝑡) {𝑥𝑦1} ℒ13 (𝑡) {𝑥𝑦2} ℒ23 (𝑡) {𝑥𝑦3} ℒ33 (𝑡)
0 1 2 3
Next, let’s look at how we could solve directly for the Bezier control points of a Bezier
Curve which interpolates those same points at those same parameters values. In this case,
we want to solve for the coefficients of a Bernstein Polynomial.
𝑛
𝑥(𝑡) 𝑛!
𝑤ℎ𝑒𝑟𝑒 𝕓(𝑡) = { } 𝑎𝑛𝑑 ℬ𝑛,𝑖 (𝑡) = 𝑡 𝑖 (1 − 𝑡)𝑛−1
𝑦(𝑡) 𝑖! (𝑛 − 𝑖)!
So;
𝕓(𝑡) = 𝕓0 ℬ0 + 𝕓1 ℬ1 + 𝕓2 ℬ2 + 𝕓3 ℬ3
𝕓(𝑡) = (1 − 𝑡)3 𝕓0 + 3𝑡(1 − 𝑡)2 𝕓1 + 3𝑡 2 (1 − 𝑡)𝕓2 + 𝑡 3 𝕓3
Since we want to generate the same parametric curve, we can apply the situation and
condition state below;
The starting point and ending point for Lagrange Polynomial and Bezier Curve is
actually the same point. So we can say that,
ℙ0 = 𝕓0 𝑎𝑛𝑑 ℙ3 = 𝕓3
Then, we need to find another two points of Bezier Curve which that point is actually the
control point of Bezier curve.
So, we apply all the conditions that we know and all known coefficient to Bernstein
Polynomial, we can find the control point of Bezier Curve.
At t = 1/3 ;
1 1 1 1 1 1
𝑝𝑥,1 = (1 − )3 𝑝𝑥,0 + 3( )(1 − )2 𝔟𝑥,1 + 3( )2 (1 − )𝔟𝑥,2 + ( )3 𝑝𝑥,3
3 3 3 3 3 3
8 4 2 1
𝑝𝑥,1 = ( ) 𝑝𝑥,0 + ( )𝔟𝑥,1 + ( )𝔟𝑥,2 + ( )𝑝𝑥,3
27 9 9 27
27𝑝𝑥,1 = 8 𝑝𝑥,0 + 12𝔟𝑥,1 + 6𝔟𝑥,2 + 𝑝𝑥,3
clear
clc
%% Calculate t
t0=0;
t1=1/3;
t2=2/3;
t3=1;
t=t0:0.01:t3;
Example:
Input: Please enter first point: [0 0]
Please enter second point: [2 2]
Please enter third point: [0 3]
Please enter forth point: [2 4]
Output:
PROBLEM STATEMENT 2
Design any meaningful sketches at least 10 pieces of curves. Use any curves that we have
learnt in class. Explanation of the curve used should be explain in the report.
Solution:
Matlab code
%% MSc. Engineering Mathematics (EQT535 CAGD)
% Universiti Malaysia Perlis
% Assignment1:Problem 2
% Picture: Batman
% by Nurul Ehsan Ramli
% date 21 February 2014
clear
clc
%% curve 1 : Aitken
%% Control points & plot
cpx=[0 1.5 2]; cpy=[-2 4 3];
hold on
%% Calculate t0, t1 and t2
t0=0;
t1=t0+sqrt((cpy(2)-cpy(1))^2+(cpx(2)-cpx(1))^2);
t2=t1+sqrt((cpy(3)-cpy(2))^2+(cpx(3)-cpx(2))^2);
t=t0:0.01:t2;
%% 1st level to calculate P01 and P11
P01x=((t1-t)/(t1-t0))*cpx(1)+((t-t0)/(t1-t0))*cpx(2);
P01y=((t1-t)/(t1-t0))*cpy(1)+((t-t0)/(t1-t0))*cpy(2);
P11x=((t2-t)/(t2-t1))*cpx(2)+((t-t1)/(t2-t1))*cpx(3);
P11y=((t2-t)/(t2-t1))*cpy(2)+((t-t1)/(t2-t1))*cpy(3);
%% 2nd level to calculate P02
P02x=((t2-t)/(t2-t0)).*P01x+((t-t0)/(t2-t0)).*P11x;
P02y=((t2-t)/(t2-t0)).*P01y+((t-t0)/(t2-t0)).*P11y;
%% Plot interpolation
plot(P02x,P02y,'k')
%% curve 2 : Aitken
%% Control points & plot
cpx=[2 3.5 3.5]; cpy=[3 4 -0.75];
hold on
%% Calculate t0, t1 and t2
t0=0;
t1=t0+sqrt((cpy(2)-cpy(1))^2+(cpx(2)-cpx(1))^2);
t2=t1+sqrt((cpy(3)-cpy(2))^2+(cpx(3)-cpx(2))^2);
t=t0:0.01:t2;
%% 1st level to calculate P01 and P11
P01x=((t1-t)/(t1-t0))*cpx(1)+((t-t0)/(t1-t0))*cpx(2);
P01y=((t1-t)/(t1-t0))*cpy(1)+((t-t0)/(t1-t0))*cpy(2);
P11x=((t2-t)/(t2-t1))*cpx(2)+((t-t1)/(t2-t1))*cpx(3);
P11y=((t2-t)/(t2-t1))*cpy(2)+((t-t1)/(t2-t1))*cpy(3);
%% 2nd level to calculate P02
P02x=((t2-t)/(t2-t0)).*P01x+((t-t0)/(t2-t0)).*P11x;
P02y=((t2-t)/(t2-t0)).*P01y+((t-t0)/(t2-t0)).*P11y;
%% Plot interpolation
plot(P02x,P02y,'k')
%% curve 3 : Aitken
%% Control points & plot
cpx=[3.5 8 3.5]; cpy=[-0.75 8 16];
hold on
%% Calculate t0, t1 and t2
t0=0;
t1=t0+sqrt((cpy(2)-cpy(1))^2+(cpx(2)-cpx(1))^2);
t2=t1+sqrt((cpy(3)-cpy(2))^2+(cpx(3)-cpx(2))^2);
t=t0:0.01:t2;
%% 1st level to calculate P01 and P11
P01x=((t1-t)/(t1-t0))*cpx(1)+((t-t0)/(t1-t0))*cpx(2);
P01y=((t1-t)/(t1-t0))*cpy(1)+((t-t0)/(t1-t0))*cpy(2);
P11x=((t2-t)/(t2-t1))*cpx(2)+((t-t1)/(t2-t1))*cpx(3);
P11y=((t2-t)/(t2-t1))*cpy(2)+((t-t1)/(t2-t1))*cpy(3);
%% 2nd level to calculate P02
P02x=((t2-t)/(t2-t0)).*P01x+((t-t0)/(t2-t0)).*P11x;
P02y=((t2-t)/(t2-t0)).*P01y+((t-t0)/(t2-t0)).*P11y;
%% Plot interpolation
plot(P02x,P02y,'k')
%% curve 4 : Aitken
%% Control points & plot
cpx=[3.5 2.5 1.5]; cpy=[16 13 17];
hold on
%% Calculate t0, t1 and t2
t0=0;
t1=t0+sqrt((cpy(2)-cpy(1))^2+(cpx(2)-cpx(1))^2);
t2=t1+sqrt((cpy(3)-cpy(2))^2+(cpx(3)-cpx(2))^2);
t=t0:0.01:t2;
%% 1st level to calculate P01 and P11
P01x=((t1-t)/(t1-t0))*cpx(1)+((t-t0)/(t1-t0))*cpx(2);
P01y=((t1-t)/(t1-t0))*cpy(1)+((t-t0)/(t1-t0))*cpy(2);
P11x=((t2-t)/(t2-t1))*cpx(2)+((t-t1)/(t2-t1))*cpx(3);
P11y=((t2-t)/(t2-t1))*cpy(2)+((t-t1)/(t2-t1))*cpy(3);
%% 2nd level to calculate P02
P02x=((t2-t)/(t2-t0)).*P01x+((t-t0)/(t2-t0)).*P11x;
P02y=((t2-t)/(t2-t0)).*P01y+((t-t0)/(t2-t0)).*P11y;
%% Plot interpolation
plot(P02x,P02y,'k')
%% curve 5 Lagrange
%% Control Point
cpx=[0 -1.5 -2]; cpy=[-2 4 3];
%% Calculate t
t0=0;
t1=t0+sqrt((cpy(2)-cpy(1))^2+(cpx(2)-cpx(1))^2);
t2=t1+sqrt((cpy(3)-cpy(2))^2+(cpx(3)-cpx(2))^2);
t=t0:0.01:t2;
%% Calculate L0, L1 and L2
L0=((t-t1).*(t-t2))/((t0-t1).*(t0-t2));
L1=((t-t0).*(t-t2))/((t1-t0).*(t1-t2));
L2=((t-t0).*(t-t1))/((t2-t0).*(t2-t1));
%% Calculate Polynomial
Px=cpx(1)*L0+cpx(2)*L1+cpx(3)*L2;
Py=cpy(1)*L0+cpy(2)*L1+cpy(3)*L2;
%% Plot curve & points
plot(Px,Py)
hold on
%% curve 6 Lagrange
%% Control Point
cpx=[-2 -3.5 -3.5]; cpy=[3 4 -0.75];
%% Calculate t
t0=0;
t1=t0+sqrt((cpy(2)-cpy(1))^2+(cpx(2)-cpx(1))^2);
t2=t1+sqrt((cpy(3)-cpy(2))^2+(cpx(3)-cpx(2))^2);
t=t0:0.01:t2;
%% Calculate L0, L1 and L2
L0=((t-t1).*(t-t2))/((t0-t1).*(t0-t2));
L1=((t-t0).*(t-t2))/((t1-t0).*(t1-t2));
L2=((t-t0).*(t-t1))/((t2-t0).*(t2-t1));
%% Calculate Polynomial
Px=cpx(1)*L0+cpx(2)*L1+cpx(3)*L2;
Py=cpy(1)*L0+cpy(2)*L1+cpy(3)*L2;
%% Plot curve & points
plot(Px,Py)
hold on
%% curve 7 Lagrange
%% Control Point
cpx=[-3.5 -8 -3.5]; cpy=[-0.75 8 16];
%% Calculate t
t0=0;
t1=t0+sqrt((cpy(2)-cpy(1))^2+(cpx(2)-cpx(1))^2);
t2=t1+sqrt((cpy(3)-cpy(2))^2+(cpx(3)-cpx(2))^2);
t=t0:0.01:t2;
%% Calculate L0, L1 and L2
L0=((t-t1).*(t-t2))/((t0-t1).*(t0-t2));
L1=((t-t0).*(t-t2))/((t1-t0).*(t1-t2));
L2=((t-t0).*(t-t1))/((t2-t0).*(t2-t1));
%% Calculate Polynomial
Px=cpx(1)*L0+cpx(2)*L1+cpx(3)*L2;
Py=cpy(1)*L0+cpy(2)*L1+cpy(3)*L2;
%% Plot curve & points
plot(Px,Py)
hold on
%% curve 8 Lagrange
%% Control Point
cpx=[-3.5 -2.5 -1.5]; cpy=[16 13 17];
%% Calculate t
t0=0;
t1=t0+sqrt((cpy(2)-cpy(1))^2+(cpx(2)-cpx(1))^2);
t2=t1+sqrt((cpy(3)-cpy(2))^2+(cpx(3)-cpx(2))^2);
t=t0:0.01:t2;
%% Calculate L0, L1 and L2
L0=((t-t1).*(t-t2))/((t0-t1).*(t0-t2));
L1=((t-t0).*(t-t2))/((t1-t0).*(t1-t2));
L2=((t-t0).*(t-t1))/((t2-t0).*(t2-t1));
%% Calculate Polynomial
Px=cpx(1)*L0+cpx(2)*L1+cpx(3)*L2;
Py=cpy(1)*L0+cpy(2)*L1+cpy(3)*L2;
%% Plot curve & points
plot(Px,Py)
hold on
%% curve 11 : Aitken
%% Control points & plot
cpx=[3 6 3.5]; cpy=[13 8 -0.75];
hold on
%% Calculate t0, t1 and t2
t0=0;
t1=t0+sqrt((cpy(2)-cpy(1))^2+(cpx(2)-cpx(1))^2);
t2=t1+sqrt((cpy(3)-cpy(2))^2+(cpx(3)-cpx(2))^2);
t=t0:0.01:t2;
%% 1st level to calculate P01 and P11
P01x=((t1-t)/(t1-t0))*cpx(1)+((t-t0)/(t1-t0))*cpx(2);
P01y=((t1-t)/(t1-t0))*cpy(1)+((t-t0)/(t1-t0))*cpy(2);
P11x=((t2-t)/(t2-t1))*cpx(2)+((t-t1)/(t2-t1))*cpx(3);
P11y=((t2-t)/(t2-t1))*cpy(2)+((t-t1)/(t2-t1))*cpy(3);
%% 2nd level to calculate P02
P02x=((t2-t)/(t2-t0)).*P01x+((t-t0)/(t2-t0)).*P11x;
P02y=((t2-t)/(t2-t0)).*P01y+((t-t0)/(t2-t0)).*P11y;
%% Plot interpolation
plot(P02x,P02y,'k')
%% curve 12 Lagrange
%% Control Point
cpx=[-3 -6 -3.5]; cpy=[13 8 -0.75];
%% Calculate t
t0=0;
t1=t0+sqrt((cpy(2)-cpy(1))^2+(cpx(2)-cpx(1))^2);
t2=t1+sqrt((cpy(3)-cpy(2))^2+(cpx(3)-cpx(2))^2);
t=t0:0.01:t2;
%% Calculate L0, L1 and L2
L0=((t-t1).*(t-t2))/((t0-t1).*(t0-t2));
L1=((t-t0).*(t-t2))/((t1-t0).*(t1-t2));
L2=((t-t0).*(t-t1))/((t2-t0).*(t2-t1));
%% Calculate Polynomial
Px=cpx(1)*L0+cpx(2)*L1+cpx(3)*L2;
Py=cpy(1)*L0+cpy(2)*L1+cpy(3)*L2;
%% Plot curve & points
plot(Px,Py)
hold on
%% curve 13 : Aitken
%% Control points & plot
cpx=[0.25 1 1.75]; cpy=[13 14 13];
hold on
%% Calculate t0, t1 and t2
t0=0;
t1=t0+sqrt((cpy(2)-cpy(1))^2+(cpx(2)-cpx(1))^2);
t2=t1+sqrt((cpy(3)-cpy(2))^2+(cpx(3)-cpx(2))^2);
t=t0:0.01:t2;
%% 1st level to calculate P01 and P11
P01x=((t1-t)/(t1-t0))*cpx(1)+((t-t0)/(t1-t0))*cpx(2);
P01y=((t1-t)/(t1-t0))*cpy(1)+((t-t0)/(t1-t0))*cpy(2);
P11x=((t2-t)/(t2-t1))*cpx(2)+((t-t1)/(t2-t1))*cpx(3);
P11y=((t2-t)/(t2-t1))*cpy(2)+((t-t1)/(t2-t1))*cpy(3);
%% 2nd level to calculate P02
P02x=((t2-t)/(t2-t0)).*P01x+((t-t0)/(t2-t0)).*P11x;
P02y=((t2-t)/(t2-t0)).*P01y+((t-t0)/(t2-t0)).*P11y;
%% Plot interpolation
plot(P02x,P02y,'k')
%% curve 14 : Aitken
%% Control points & plot
cpx=[0.25 1 1.75]; cpy=[13 12 13];
hold on
%% Calculate t0, t1 and t2
t0=0;
t1=t0+sqrt((cpy(2)-cpy(1))^2+(cpx(2)-cpx(1))^2);
t2=t1+sqrt((cpy(3)-cpy(2))^2+(cpx(3)-cpx(2))^2);
t=t0:0.01:t2;
%% 1st level to calculate P01 and P11
P01x=((t1-t)/(t1-t0))*cpx(1)+((t-t0)/(t1-t0))*cpx(2);
P01y=((t1-t)/(t1-t0))*cpy(1)+((t-t0)/(t1-t0))*cpy(2);
P11x=((t2-t)/(t2-t1))*cpx(2)+((t-t1)/(t2-t1))*cpx(3);
P11y=((t2-t)/(t2-t1))*cpy(2)+((t-t1)/(t2-t1))*cpy(3);
%% 2nd level to calculate P02
P02x=((t2-t)/(t2-t0)).*P01x+((t-t0)/(t2-t0)).*P11x;
P02y=((t2-t)/(t2-t0)).*P01y+((t-t0)/(t2-t0)).*P11y;
%% Plot interpolation
plot(P02x,P02y,'k')
%% curve 15 Lagrange
%% Control Point
cpx=[-0.25 -1 -1.75]; cpy=[13 14 13];
%% Calculate t
t0=0;
t1=t0+sqrt((cpy(2)-cpy(1))^2+(cpx(2)-cpx(1))^2);
t2=t1+sqrt((cpy(3)-cpy(2))^2+(cpx(3)-cpx(2))^2);
t=t0:0.01:t2;
%% Calculate L0, L1 and L2
L0=((t-t1).*(t-t2))/((t0-t1).*(t0-t2));
L1=((t-t0).*(t-t2))/((t1-t0).*(t1-t2));
L2=((t-t0).*(t-t1))/((t2-t0).*(t2-t1));
%% Calculate Polynomial
Px=cpx(1)*L0+cpx(2)*L1+cpx(3)*L2;
Py=cpy(1)*L0+cpy(2)*L1+cpy(3)*L2;
%% Plot curve & points
plot(Px,Py)
hold on
%% curve 16 Lagrange
%% Control Point
cpx=[-0.25 -1 -1.75]; cpy=[13 12 13];
%% Calculate t
t0=0;
t1=t0+sqrt((cpy(2)-cpy(1))^2+(cpx(2)-cpx(1))^2);
t2=t1+sqrt((cpy(3)-cpy(2))^2+(cpx(3)-cpx(2))^2);
t=t0:0.01:t2;
%% Calculate L0, L1 and L2
L0=((t-t1).*(t-t2))/((t0-t1).*(t0-t2));
L1=((t-t0).*(t-t2))/((t1-t0).*(t1-t2));
L2=((t-t0).*(t-t1))/((t2-t0).*(t2-t1));
%% Calculate Polynomial
Px=cpx(1)*L0+cpx(2)*L1+cpx(3)*L2;
Py=cpy(1)*L0+cpy(2)*L1+cpy(3)*L2;
%% Plot curve & points
plot(Px,Py)
hold on
Explanations