Stresses Calculator - Our 9th Symphony 🤩
itsLu
matlab
2 years ago
5.1 kB
34
Indexable
% Code that executes after component creation
function startupFcn(app)
movegui(app.StressesCalculatorTeam2UIFigure, 'center');
app.InputParametersPanel.BorderColor = [0.09,0.42,0.53];
app.OutputparametersPanel.BorderColor = [0.09,0.42,0.53];
app.RotationStressesPanel.BorderColor = [0.09,0.42,0.53];
app.MaximumShearStressPanel.BorderColor = [0.09,0.42,0.53];
app.PrincipalStressesPanel.BorderColor = [0.09,0.42,0.53];
end
% Button pushed function: CalculateParametersDrawCircleButton
function CalculateParametersDrawCircleButtonPushed(app, event)
% Inputs:
Sigma_x = app.Sigma_xEditField.Value;
Sigma_y = app.Sigma_yEditField.Value;
Shear = app.Shear_xyxyEditField.Value;
RotationAngle = app.RotationAngleEditField.Value;
% Calculations:
Sigma_x1 = ((Sigma_x+Sigma_y)/2) + (((Sigma_x-Sigma_y)/2)*cosd(2*RotationAngle)) + (Shear*sind(2*RotationAngle));
Sigma_y1 = ((Sigma_x+Sigma_y)/2) - (((Sigma_x-Sigma_y)/2)*cosd(2*RotationAngle)) - (Shear*sind(2*RotationAngle));
Shear_xy = ((-(Sigma_x-Sigma_y)/2)*sind(2*RotationAngle)) + (Shear*cosd(2*RotationAngle));
Sigma1 = ((Sigma_x+Sigma_y)/2) + sqrt((((Sigma_x-Sigma_y)/2)^2)+ Shear^2);
Sigma2 = ((Sigma_x+Sigma_y)/2) - sqrt((((Sigma_x-Sigma_y)/2)^2)+ Shear^2);
a=Sigma_x-Sigma_y;
b=Shear;
c=2*(b/a);
d=atand(c);
Theta_p1=d/2;
Theta_p2 = Theta_p1+90;
s = atand(-a/(2*b));
Theta_s1 = s/2;
Theta_s2 = Theta_s1 + 90;
MaximumShear = sqrt((((Sigma_x-Sigma_y)/2)^2)+ Shear^2);
% Output:
app.Sigma_x1EditField.Value = Sigma_x1;
app.Sigma_y1EditField.Value = Sigma_y1;
app.Shear_x1y1EditField.Value = Shear_xy;
app.Sigma1EditField.Value = Sigma1;
app.Sigma2EditField.Value = Sigma2;
app.Theta_p1EditField.Value = Theta_p1;
app.Theta_p2EditField.Value = Theta_p2;
app.MaximumShearEditField.Value = MaximumShear;
app.Theta_s1EditField.Value = Theta_s1;
app.Theta_s2EditField.Value = Theta_s2;
% Mohr's Circle:
% Resetting Axes
cla(app.UIAxes);
% Computing Radius and Center of the circle
R=sqrt((a/2)^2+Shear^2);
C=(Sigma_x+Sigma_y)/2;
% Customize axes labels and properties
xlabel(app.UIAxes, 'Sigma');
ylabel(app.UIAxes, 'Shear Stress');
% Fix aspect ratio to ensure circle looks correct
axis(app.UIAxes, 'equal');
% Calculate the limits for the y axis
yMin = -R; % Minimum y-coordinate (assuming center at y=0)
yMax = R; % Maximum y-coordinate (assuming center at y=0)
% Set the limits of the axes to include a margin around the circle
margin = 0.1 * R; % Adjust this value as needed for desired margin
%xlim(app.UIAxes, [xMin - margin, xMax + margin]);
ylim(app.UIAxes, [yMin - margin, yMax + margin]);
% Holding app.UIAxes
hold(app.UIAxes, 'on');
% Add diameters for principal stresses and initial stress state
plot(app.UIAxes, [Sigma_x, Sigma_y], [Shear, -Shear], 'r');
plot(app.UIAxes, [Sigma_x1, Sigma_y1], [Shear_xy, -Shear_xy], 'g');
% Generate angles for drawing the circle
theta = linspace(0, 2*pi, 100);
% Calculate x and y coordinates of the circle
x = C + R * cos(theta);
y = R * sin(theta);
% Plot the circle on the UIAxes
plot(app.UIAxes, x, y, 'k', 'LineWidth', 2);
% Enable grid for better visualization
grid(app.UIAxes, 'on');
% Release the hold on app.UIAxes
hold(app.UIAxes, 'off');
% Turn Visibility on
if app.StressesCalculatorTeam2UIFigure.Position(3) == 320
app.OutputparametersPanel.Visible = "on";
app.StressesCalculatorTeam2UIFigure.Position = [0,0,629,480];
movegui(app.StressesCalculatorTeam2UIFigure, 'center');
app.InputParametersPanel.Position = [31,281,260,170];
app.OutputparametersPanel.Position = [341, 31, 260, 420];
app.CalculateParametersDrawCircleButton.Position = [56, 249, 212, 23];
app.UIAxes.Position = [21, 33, 300, 208];
app.UIAxes.PlotBoxAspectRatio = [1,0.8566176470588235,0.8566176470588235];
app.UIAxes.Visible = "on";
app.UIAxes.Toolbar.Visible = "on";
end
Editor is loading...
Leave a Comment