%% Shear stress
%
%
%
%
% The average shear stress is given by
% \tau =\frac{T}{A}
% where T denotes the shear force and is tangential to the shear plane, A is the area on which the shearing acts.
%% Example 1
%
% Determine the shear stress in the cylindrical pin with a cross sectional area of A subjected to a force P.
% Solution
% FBD of the pin
%
% \left\lbrace \begin{array}{ll}
% P-2T=0 & \\
% \tau =\frac{T}{A} &
% \end{array}\right.
% \Rightarrow T=\frac{P}{2},\tau =\frac{P}{2A}
%% Example 2
%
% Determine the stresses in the cut at an angle \varphi. At which angle do we get the highest shear stress? Plot!
% Solution
% Cut and FBD
% Forces:
%
% and stresses
%
% \left\lbrace \begin{array}{ll}
% N\;\sin \varphi +T\;\cos \varphi -P=0 & \\
% -N\;\cos \varphi +T\;\sin \varphi =0 & \\
% \sigma_{\varphi } =\frac{N}{A/\sin \varphi } & \\
% \tau_{\varphi } =\frac{T}{A/\sin \varphi } &
% \end{array}\right.
% \Rightarrow P\;\sin \varphi ,T=P\;\sin \varphi ,\sigma_{\varphi } =\frac{P\;\sin^2 \varphi }{A},\tau_{\varphi } =\frac{P\;\sin \varphi \;\cos \varphi }{A}

clear
syms N T varphi P A sigma_varphi tau_varphi

eq = [N*sin(varphi) + T*cos(varphi) - P == 0
      -N*cos(varphi) + T*sin(varphi) == 0
      sigma_varphi == N/(A/sin(varphi))
      tau_varphi == T/(A/sin(varphi))]
[N,T,sigma_varphi,tau_varphi] = solve(eq, [N,T,sigma_varphi,tau_varphi]);
simplify([N,T,sigma_varphi,tau_varphi])
P = 1; A = 1;


figure; hold on
fplot(subs(N), [0,pi/2], 'linewidth', 2, 'DisplayName', '$N/P$')
fplot(subs(T), [0,pi/2], 'linewidth', 2, 'DisplayName', '$T/P$')
fplot(subs(sigma_varphi), [0,pi/2], 'linewidth', 2, 'DisplayName', '$\sigma_\varphi A / P$')
fplot(subs(tau_varphi), [0,pi/2], 'linewidth', 2, 'DisplayName', '$\tau_\varphi A / P$')
legend('Interpreter','latex')
xlabel('$\varphi$', 'Interpreter','latex')

% As we can see, the maximum shear stress is at \frac{\pi }{4}={45}^{\circ }.
%% Example 3
%
% Dimension the pin in A and in B is the maximum allowable shear stress is 180MPa, use a safety factor of 1.5.
% Solution
% FBD of the rigid beam.
%
% Equilibrium equations give:
% \left\lbrace \begin{array}{ll}
% \sum M_A =0:F_{\mathrm{By}} r_{\mathrm{AB}} -F_G r_{\mathrm{AG}} =0 & \Rightarrow F_B \frac{4}{5}\cdot 6-30000\cdot 2=0\\
% \to :F_{\mathrm{Bx}} -A_x =0 & \Rightarrow F_B \frac{3}{5}=A_x \\
% \uparrow :A_y -F_G +F_{\mathrm{By}}  & \Rightarrow A_y =30000-F_B \frac{4}{5}
% \end{array}\right.
% F_A =|\left\lbrack A_x ,A_y \right\rbrack |=\sqrt{A_x^2 +A_y^2 }
%
% V_A =\frac{1}{2}F_A
% \tau_A =\frac{V_A }{A_A }\Rightarrow A_A =\frac{\tau_A }{V_A }={\left(\frac{d_A }{2}\right)}^2 \pi
%
% V_B =F_B
% \tau_B =\frac{V_B }{A_B }=\frac{V_B }{{\left(\frac{d_B }{2}\right)}^2 \pi }

clear
syms d_A positive
F_A = 21360
tau = 180e6/1.5 %% N/m
V_A = 1/2*F_A;
d_A = solve(tau == V_A / ( (d_A/2)^2*pi) , d_A)
d_A = vpa(d_A) %m
d_A = d_A*1000 %mm

syms d_B positive
V_B = 12500; %N
d_B = solve(tau == V_B/( (d_B/2)^2*pi ), d_B)
d_B = vpa(d_B) %m
d_B = d_B*1000 %mm

% Conclusion: The pin in A needs to be at least 11mm and the pin in B needs to be at least 12mm. For easier manufacturing, just use 12mm pins in both connections.
%
%
%
%
%
%