51 views (last 30 days)

Show older comments

In this figure I would like to fit a semi-circle on the green curve

The ref code for plotting semi-circle is as follows

function Circ = semi_circle(xc,yc,R,flag)

theta=linspace(pi/2,-pi/2,100);

xcircle = R*cos(theta')+xc;

ycircle = R*sin(theta')+yc;

if flag

plot(xcircle,ycircle);

end

Circ=[xcircle,ycircle];

end

xc,yc and R are obtained as follows

First compute normals for left seg 1 using LineNormals2D,then project the points on left seg1 using the angles in LineNormals2D I will then look at where these projections intersect left_seg2 using InterX. The intersectin point will be the center and the distance between the center and the poin t on left seg 1 will be radius

The green points are enclosed left_seg1 and left_seg2.

Any help/suggestions will be appreciated.

Matt J
on 22 Sep 2021 at 17:16

I recommend circularFit from

In addition to doing more careful data pre-normalization than the Bucher Izhak code routine, it contains methods for post-plotting the fit.

>> fobj=circularFit([left_seg,left_seg2])

fobj =

circularFit with properties:

center: [133.7487 51.8286]

radius: 4.3551

>> plot(fobj)

Image Analyst
on 22 Sep 2021 at 17:40

Image Analyst
on 22 Sep 2021 at 12:38

I'd suggest you use the FAQ to fit a circle through the points you have circled:

function [xCenter, yCenter, radius, a] = circlefit(x, y)

% circlefit(): Fits a circle through a set of points in the x - y plane.

% USAGE :

% [xCenter, yCenter, radius, a] = circlefit(X, Y)

% The output is the center point (xCenter, yCenter) and the radius of the fitted circle.

% "a" is an optional output vector describing the coefficients in the circle's equation:

% x ^ 2 + y ^ 2 + a(1) * x + a(2) * y + a(3) = 0

% by Bucher Izhak 25 - Oct - 1991

numPoints = numel(x);

xx = x .* x;

yy = y .* y;

xy = x .* y;

A = [sum(x), sum(y), numPoints;

sum(xy), sum(yy), sum(y);

sum(xx), sum(xy), sum(x)];

B = [-sum(xx + yy) ;

-sum(xx .* y + yy .* y);

-sum(xx .* x + xy .* y)];

a = A \ B;

xCenter = -.5 * a(1);

yCenter = -.5 * a(2);

radius = sqrt((a(1) ^ 2 + a(2) ^ 2) / 4 - a(3));

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!