The coding that I have been using so far is the following, there I have the main line F(x)=mx+b, the semicircle and a perpendicular, where the perpendicular should be the same lenght as R (radius of the semicircle).
So what I want to do is to find an intersection point for the three lines (P=pl) by modifying R and r and making them the same.
%Main line
warning off; close all;clc;
SS=[2393.9 3733.3 4638.6];
NS=[1875.4 3080 4210.2];
c=polyfit(NS,SS,1); % Here 'c' contains the 'm' and 'b'
SS_est=polyval(c,NS);
plot(NS,SS,'*');
grid
title(['Line Equation is y = ',num2str(c(1)),'*x + ','(',num2str(c(2)),')']);
xlabel('Normal Stress(Pa)');
ylabel('Shear stress (Pa)');
hold on
plot(NS,SS_est);
m=c(1);
b=c(2);
xl = linspace(0,4500);
f = @(xl) m*xl+b;
figure(1)
plot(xl, f(xl))
grid
% Choose a point C along line AB at half distance
D(1) = range([NS(1),SS_est(1)])/2+min([NS(1),SS_est(1)]);
D(2) = m*D(1) + b;
% Get slope and y int of line perpendicular to AB at point C
perp = -1/m;
% Find the end points of the perpendicular line with length Clen*2
a = D(1)+ (1000*sqrt(1/(1+perp^2)))*[-1,1];
b = [D(2)+ (perp*sqrt(1/(1+perp^2))),0];
plot(a,b)
perpe=[a;b];
legend('Data','Fitted Curve','Location','northwest');
disp(['Line Equation is y = F(x) = ',num2str(c(1)),'*x + ','(',num2str(c(2)),')']);
T = table(NS',SS',SS_est',(SS-SS_est)','VariableNames',{'Frequency','Activation_Energy','Fit','Fit_Error_R'})
% Semi circle
th = linspace( -pi*2, -pi, R);
R = 2000; %Radius
x = R*cos(th) + R;
y = R*sin(th);
circ=[x;y];
plot(x,y); axis equal;
%Intersections
L1=[xl;f(xl)];
pl=InterX(perpe,L1);
P=InterX(circ,L1);
r= sum(sqrt(diff(pl).^2+diff(b).^2));