%Mohr's Circle Program
%2-D plotting for known
%sigmax = Normal Stress in x direction
%sigmay = Normal stress in y direction
%tauxy = shear stress in x,y direction
clc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Input Section%
sigmax = input('sigma_{x}) [ksi], =');
sigmay = input('sigma_{y}) =');
tauxy = input('tau_{xy}) , - if ccw =');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%Calculations%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Calculation of Center [Sigma]
sigma = (sigmax+sigmay)/2;
%Calculation of the radius of the circle [R]
R = (((sigmax-sigmay)/2)^2+tauxy^2)^0.5
tau1 = +R
tau2 = -R
%Principle Stress Calculation
sigma1 = sigma + R
sigma2 = sigma - R
%Oblique angle from sigma axis [phi_p]
phi_p = 0.5*atan(2*tauxy/((sigmax-sigmay)))*180/(pi)
%Angle complentary to phi_p
phi_s = 0.5*atan(-((sigmax-sigmay)/(2*tauxy)))*180/(pi)
%%%%%%%%%%%%%%%%%%%%%%%Circle%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Preliminary data of the Circle
x0 = sigma; % x center of circle
y0 = 0; % y center of circle
N = 100; % number of points used to define circle
% create equal length arrays defining a circle in polar coordinates
theta = linspace(0,2*pi,N);
r = R * ones(1,N);
% convert polar coordinates to Cartesian coordinates
[x, y] = pol2cart(theta, r);
% offset the circle so its center lies at (x0, y0)
x = x + x0;
y = y + y0;
%%%%%%%%%%%%%%%%%%%%%%Line created from phi%%%%%%%%%%%%%%%%%%%%%%%%%%%
%obtained through point slope formulation
x1 = sigma2:1:sigma1;
y1 =(tauxy/(R-sigma))*x1 - (tauxy/(R-sigma))*sigma;
x2= sigma2:1:sigma1;
y2=0;
x3=sigma;
y3= -R:1:R;
%Plotting
plot(x,y,'b-',x1,y1,'r-', x2,y2,'y.', x3 ,y3, 'y.');
title('Mohrs 2D Circle')
xlabel('\sigma \rightarrow [ksi]')
ylabel('\tau^{cw} \rightarrow [ksi]')
grid on
axis equal
%Center Label
xC= sigma;
yC= 0;
txtC='\sigma';
text(xC,yC,txtC)
%%%%%Labeling of principle stress%%%%
%Sigma 1
xa = sigma1;
ya = 0;
txt1 = '\leftarrow \sigma_{1}';
text(xa,ya,txt1)
%Sigma 2
xb = sigma2;
yb = 0;
txt2 = '\leftarrow \sigma_{2}';
text(xb,yb,txt2)
%%%%%Point of Intersection of circle%%%%%
x3 = R;
y3 = tauxy;
txt3 = 'R, \tau_{xy}';
text(x3,y3,txt3)
%%%%%%%%%%%%%%%%%MADE BY JOSEPH FUENTES%%%%%%%%%%%%%%%%%%%