已知三个控制点:B样条曲线和圆弧曲线

文章介绍了如何使用B样条曲线和自定义Mymethod函数来生成圆弧曲线,并通过代码示例展示了如何在图形中绘制控制点、B样条曲线和Mymethod曲线的对比。
摘要由CSDN通过智能技术生成

圆弧曲线

function curve=mymethod(points1,NT,c1,c0,speed)
px=zeros(2*NT,1);
py=zeros(2*NT,1);
px(1)=points1(1);
py(1)=points1(2);
temp=NT/tan(abs(c1-c0)/2);
R=temp*speed;
for i=2:2*NT
    wt=1/temp*(i-1);
    if c1-c0>0
        px(i) = points1(1) + R* sin(wt)*cos(c0)-(R-R*cos(wt))*sin(c0);
        py(i) = points1(2) + R* sin(wt)*sin(c0)+(R-R*cos(wt))*cos(c0);
    else
        px(i) = points1(1) + (R-R*cos(wt))*sin(c0)+R* sin(wt)*cos(c0);
        py(i) = points1(2) + R*sin(wt)*sin(c0)-(R-R*cos(wt))*cos(c0);
    end
end
curve=[px,py];
end

B样条曲线

function curve = bspline(points, t)
    n = size(points, 1) - 1;
    curve = zeros(length(t), 2);
    for i = 1:length(t)
        for j = 0:n
            blend = nchoosek(n, j) * t(i)^j * (1-t(i))^(n-j);
            curve(i,:) = curve(i,:) + blend * points(j+1,:);
        end
    end
end

 调用函数

NT=20;
v=0.0257;
c0=0.351;
c1=1.75;
point1=[0,0];
point2=point1+[NT*v*cos(c0),NT*v*sin(c0)];
point3=point2+[NT*v*cos(c1),NT*v*sin(c1)];
% Define control points
points = [point1;point2;point3];

% B-spline
t = 0:0.01:1;
bspline_curve = bspline(points, t);

% Bezier curve
% bezier_curve = bezier(points, t);
mymethod_curve=mymethod(point1,NT,c1,c0,v);

% Plot curves
figure;
hold on;
plot(points(:,1), points(:,2), 'o-', 'LineWidth', 2);
plot(bspline_curve(:,1), bspline_curve(:,2), 'r', 'LineWidth', 2);
hold on
% plot(bezier_curve(:,1), bezier_curve(:,2), 'g', 'LineWidth', 2);
plot(mymethod_curve(:,1), mymethod_curve(:,2), 'g', 'LineWidth', 2);
xlim([0,1]);
ylim([0,1]);
legend('Control Points', 'B-spline Curve', 'Mymethod Curve');
xlabel('X');
ylabel('Y');
title('B-spline vs Mymethod Curve');

参考文献:

从零开始学图形学:10分钟看懂贝塞尔曲线 - 知乎 (zhihu.com)

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值