# 基于matlab过已知三点做圆

### 时间：2018-3-1 23:39:28 点击：

核心提示：基于matlab过已知三点做圆 ...

if nargin < 3
error('Three input points are required.');
elseif ~isequal(numel(pt1),numel(pt2),numel(pt3),2)
error('The three input points should all have two elements.')
end

pt1 = double(pt1);
pt2 = double(pt2);
pt3 = double(pt3);

epsilon = 0.000000001;

delta_a = pt2 - pt1;
delta_b = pt3 - pt2;

ax_is_0 = abs(delta_a(1)) <= epsilon;
bx_is_0 = abs(delta_b(1)) <= epsilon;

% check whether both lines are vertical - collinear
if ax_is_0 && bx_is_0
centre = [0 0];
warning([mfilename ':CollinearPoints'],'Points are on a straight line (collinear).');
return
end

% make sure delta gradients are not vertical
% swap points to change deltas
if ax_is_0
tmp = pt2;
pt2 = pt3;
pt3 = tmp;
delta_a = pt2 - pt1;
end
if bx_is_0
tmp = pt1;
pt1 = pt2;
pt2 = tmp;
delta_b = pt3 - pt2;
end

grad_a = delta_a(2) / delta_a(1);
grad_b = delta_b(2) / delta_b(1);

% check whether the given points are collinear
centre = [0 0];
warning([mfilename ':CollinearPoints'],'Points are on a straight line (collinear).');
return
end

% swap grads and points if grad_a is 0
if abs(grad_a) <= epsilon
tmp = pt1;
pt1 = pt3;
pt3 = tmp;
end

% calculate centre - where the lines perpendicular to the centre of
% segments a and b intersect.
centre(2) = ((pt1(1)+pt2(1))/2 - centre(1)) / grad_a + (pt1(2)+pt2(2))/2;

radius = norm(centre - pt1);

• 百度搜索
• 查阅资料过程中
• 论坛发现
• 百度贴吧发现
• 朋友介绍
• 没有相关文章
• 大名：
• 内容：