You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
2.0 KiB
61 lines
2.0 KiB
%--------------------------
|
|
% @Author: Jingqiao Hu
|
|
% @Date: 2021-06-06 14:26:46
|
|
% @LastEditTime: 2021-06-06 15:55:17
|
|
%--------------------------
|
|
|
|
x0 = 0;
|
|
x1 = 1;
|
|
x01 = 0.5;
|
|
x10 = 0.5;
|
|
n = 100;
|
|
dx = (x1-x0) / n;
|
|
|
|
y0 = 1;
|
|
y1 = -1;
|
|
y01 = 3;
|
|
y10 = -3;
|
|
Q = [x0, 0, x01, 0, x10, 0, x1, 0;
|
|
0, y0, 0, y01, 0, y10, 0, y1]';
|
|
|
|
y = zeros(n+1, 2);
|
|
for i = 0:n
|
|
t = i*dx;
|
|
B = Bezier_matrix(t);
|
|
y(i+1, :) = diag(B * Q);
|
|
end
|
|
|
|
figure;
|
|
plot(y(:,1), y(:,2), 'k','linewidth',2);
|
|
hold on; plot([x0,x0],[0,y0],':','Color', 'k','linewidth',2); plot([x1,x1],[0,y1],':','Color', 'k','linewidth',2);
|
|
plot([x0-0.1, x1+0.1], [0,0], 'k','linewidth',1);
|
|
plot([x0,x01],[y0,y01],':','Color', 'k','linewidth',2); plot([x10,x1],[y10,y1],':','Color', 'k','linewidth',2);
|
|
scatter([x0,x01,x10,x1],[y0,y01,y1,y1], 'MarkerEdgeColor','k', 'MarkerFaceColor',[1,1,1], 'LineWidth',2);
|
|
xlabel('X','Color','k','FontSize',16);
|
|
% ylabel('Y','Color','k','FontSize',16);
|
|
ylim([-2.5,2.5]);
|
|
|
|
figure; plot([x0,0.2,0.8,x1], [y0,1.414,-1.414,y1], 'k','linewidth',2);
|
|
hold on; plot([x0,x0],[0,y0],':','Color', 'k','linewidth',2); plot([x1,x1],[0,y1],':','Color', 'k','linewidth',2);
|
|
plot([x0-0.1, x1+0.1], [0,0], 'k','linewidth',1);
|
|
scatter([x0,0.2,0.8,x1], [y0,1.414,-1.414,y1], 'MarkerEdgeColor','k', 'MarkerFaceColor',[1,1,1], 'LineWidth',2);
|
|
xlabel('X','Color','k','FontSize',16);
|
|
% ylabel('Y','Color','k','FontSize',16);
|
|
ylim([-2.5,2.5])
|
|
|
|
figure; plot([x0,x1], [y0,y1], 'k','linewidth',2);
|
|
hold on; plot([x0,x0],[0,y0],':','Color', 'k','linewidth',2); plot([x1,x1],[0,y1],':','Color', 'k','linewidth',2);
|
|
plot([x0-0.1, x1+0.1], [0,0], 'k','linewidth',1);
|
|
scatter([x0,x1],[y0,y1], 'MarkerEdgeColor','k', 'MarkerFaceColor',[1,1,1], 'LineWidth',2);
|
|
xlabel('X','Color','k','FontSize',16);
|
|
ylabel('Y','Color','k','FontSize',16);
|
|
ylim([-2.5,2.5])
|
|
|
|
function B = Bezier_matrix(t)
|
|
B = [1, t, t^2, t^3] * [1, 0,0,0;
|
|
-3,3,0,0;
|
|
3,-6,3,0;
|
|
-1,3,-3,1]; % 1,4
|
|
I = eye(2, 2);
|
|
B = kron(B, I); % 2,8
|
|
end
|