matlab根据三维点花圆弧,MATLAB 平面三点生成圆弧

MATLAB新手,最近要写一个程序,参考了多个百度的结果以及https://blog.csdn.net/libing403/article/details/78234640?utm_source=blogxgwz6这篇文章提供的方法,自己想了一个办法,目前测试过的点都成功了,所以想给大家分享一下。欢迎大家指出错误和不足(๑╹◡╹)ノ"""。

%判断是圆还是圆弧

if get(handles.rad_round_1,'value')

round_flag=1;

elseif get(handles.rad_round_2,'value')

round_flag=2;

else

warndlg('请选择圆或圆弧^-^','提示','modal')

end

%输入三个点的坐标

%%获取三点所在圆圆心及半径

x0=[x1 x2 x3]';

y0=[y1 y2 y3]';

TR=triangulation([1,2,3],x0,y0); %表示成三角网格

[D,r]=circumcenter(TR); %利用内置函数求外接圆心和半径

a=D(1);b=D(2); %圆心(a,b) 半径 r

%开始生成

switch(round_flag)

case 1 %根据圆心半径生成圆

deg=0:0.01:360;

rx=a+r*cos(deg);

ry=b+r*sin(deg);

plot(a,b,'*r');hold on;

plot(x0,y0,'ro');hold on;

plot(rx,ry,'g');hold on;

case 2 %根据圆心半径生成圆弧

A=[x1 y1 0];B=[x2 y2 0];C=[x3 y3 0];

AB=B-A;BC=C-B;

dis=cross(AB,BC);

if dis(3)==0

warndlg('三点共线,请重新输入坐标^-^','提示','modal')

else

e=c_theta(x1,y1,a,b);

f=c_theta(x2,y2,a,b);

g=c_theta(x3,y3,a,b);

if max(max(e,f),g)==e

if f>g

deg=e:-0.1:g;

else

deg=e:0.1:(360+g);

end

elseif max(max(e,f),g)==f

if e>g

deg=e:0.1:(g+360);

else

deg=e:-0.1:(g-360);

end

elseif max(max(e,f),g)==g

if e>f

deg=e:-0.1:(g-360);

else

deg=e:0.1:g;

end

end

rx=a+r*cosd(deg);

ry=b+r*sind(deg);

plot(a,b,'*r');hold on;

plot(x0,y0,'ro');hold on;

plot(rx,ry,'g');hold on;

end

end

set(gca,'XAxisLocation','origin');

set(gca,'YAxisLocation','origin');

axis equal

hold on;grid on;

%判断输入点的角度

function theta=c_theta(x,y,a,b)

theta=atand((y-b)/(x-a));

if x >= a

if y >= b

theta=theta; %第一象限

elseif y= b

theta=theta+180; %第二象限

elseif y

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值