Skip to content

Commit 39feb14

Browse files
refactor(plot): remove loading diagram and enhance shear/moment plots
This commit simplifies the visualization output by removing the loading diagram. The logic to plot distributed loads, point forces, and concentrated moments was complex and cluttered the main script, detracting from the primary goal of generating shear and moment diagrams. The key changes include: - Eliminating the 'Loading Diagram' subplot entirely. - Adjusting the figure layout from a 3x1 to a 2x1 grid. - Standardizing plot colors and adding boxes for improved clarity. - Introducing a fix to handle potential NaN values in the shear vector to prevent plot failures. - Enforcing that shear and moment diagrams end at zero, which is a common boundary condition for simply supported beams.
1 parent 532b2cc commit 39feb14

1 file changed

Lines changed: 27 additions & 53 deletions

File tree

shear_moment_diagrammer/main.m

Lines changed: 27 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
clc; clear; close all;
1+
close all;
22

33
%% User Inputs & Problem Definition
44
% Prompt the user to define the beam's physical properties and loads.
@@ -18,7 +18,7 @@
1818
exponents = []; % Vector for 'n' values
1919

2020
%% Pre-processing: Standardize Operators
21-
% This step remains crucial. We replace all subtractions with "plus negative"
21+
% Replace all subtractions with "plus negative"
2222
% to ensure the sign is correctly associated with its magnitude 'q'.
2323
% Example: "A - B" becomes "A + -B"
2424
no_space_str = erase(input_str, whitespacePattern);
@@ -85,7 +85,7 @@
8585
% expression becomes zero.
8686
singularity = @(x, a, n) (n >= 0) .* (x > a) .* (x - a).^n;
8787

88-
%% 2. Programmatic and Automated Calculation
88+
%% Programmatic and Automated Calculation
8989
% This advanced version replaces the switch-case with a universal mathematical
9090
% rule for singularity function integration, making the code more concise
9191
% and scalable.
@@ -96,12 +96,7 @@
9696
a = offsets(i);
9797
n = exponents(i);
9898

99-
% --- Contribuição para a CURVA de Carregamento (apenas n >= 0) ---
100-
if n >= 0
101-
q_plot = q_plot + q * singularity(x, a, n);
102-
end
103-
104-
% --- Universal Integration Rules ---
99+
% Universal Integration Rules
105100

106101
% Contribution to Shear (V)
107102
v_exp = n + 1;
@@ -114,73 +109,52 @@
114109
M = M + (q / m_den) * singularity(x, a, m_exp);
115110
end
116111

117-
% --- Bloco de Plotagem Aprimorado ---
118112

119-
% Invertendo a convenção de sinais (conforme seu código)
113+
114+
%% Enhanced Plotting Block
115+
116+
% Inverting the sign convention (as per your code)
120117
V = -V;
121118
M = -M;
122119

123-
% Cria o vetor para a linha do eixo zero
120+
nan_index = find(isnan(V));
121+
V(nan_index) = V(nan_index - 1);
122+
123+
V(end) = 0; M(end) = 0;
124+
125+
%dyna_padder = @(in_vector) max([abs(min(in_vector)), max(in_vector)]);
126+
127+
% Creates the vector for the zero-axis line
124128
y = zeros(size(x));
125129

126130
figure('Name', 'Beam Analysis Diagrams');
127131

128-
% --- Loading Diagram (q) ---
129-
subplot(3, 1, 1);
130-
% Plota a curva das cargas distribuídas
131-
plot(x, q_plot, 'b', 'LineWidth', 1.5);
132-
hold on;
133-
plot(x, y, 'k--');
134-
grid on;
135-
title('Loading Diagram');
136-
ylabel('Load (N)');
137-
fill([x, fliplr(x)], [q_plot, fliplr(y)], 'b', 'FaceAlpha', 0.3, 'EdgeColor', 'none');
138-
% Agora, adiciona as forças e momentos concentrados
139-
for i = 1:length(magnitudes)
140-
q = magnitudes(i);
141-
a = offsets(i);
142-
n = exponents(i);
143-
144-
if n == -1 % Força Pontual
145-
if q > 0 % Seta para cima
146-
plot([a, a], [-0.1*max(abs(ylim)), 0], 'b', 'LineWidth', 1.5);
147-
plot(a, -0.1*max(abs(ylim)), 'b^', 'MarkerFaceColor', 'b', 'MarkerSize', 8);
148-
else % Seta para baixo
149-
plot([a, a], [0.1*max(abs(ylim)), 0], 'r', 'LineWidth', 1.5);
150-
plot(a, 0.1*max(abs(ylim)), 'rv', 'MarkerFaceColor', 'r', 'MarkerSize', 8);
151-
end
152-
text(a, -8, sprintf('%.1f', q), 'HorizontalAlignment', 'center');
153-
elseif n == -2 % Momento Concentrado
154-
if q > 0 % Anti-horário
155-
text(a, 0.1*max(abs(ylim)), '\circlearrowleft', 'Color', 'g', 'FontSize', 16, 'HorizontalAlignment', 'center', 'FontWeight', 'bold', 'Interpreter', 'latex');
156-
else % Horário
157-
text(a, 0.1*max(abs(ylim)), '\circlearrowright', 'Color', 'g', 'FontSize', 16, 'HorizontalAlignment', 'center', 'FontWeight', 'bold', 'Interpreter', 'latex');
158-
end
159-
text(a, -0.2*max(abs(ylim)), sprintf('M=%.1f', q), 'HorizontalAlignment', 'center');
160-
end
161-
end
162-
hold off;
163-
164132
% Shear Force Diagram
165-
subplot(3, 1, 2);
166-
plot(x, V, 'm', 'LineWidth', 1.5);
133+
subplot(2, 1, 1);
134+
plot(x, V, 'LineWidth', 1.5, 'Color', 'b');
167135
hold on;
168136
plot(x, y, 'k--');
169137
grid on;
138+
box on;
170139
title('Shear Force Diagram');
171140
ylabel('Shear Force (N)');
172141
xlabel('Position (x)');
173-
fill([x, fliplr(x)], [V, fliplr(y)], 'm', 'FaceAlpha', 0.3, 'EdgeColor', 'none');
142+
fill([x, fliplr(x)], [V, fliplr(y)], 'b', 'FaceAlpha', 0.3, 'EdgeColor', 'none');
143+
xlim([min(x) max(x)]);
144+
ylim([min(V) max(V)]);
174145
hold off;
175146

176147
% Bending Moment Diagram
177-
subplot(3, 1, 3);
178-
plot(x, M, 'r', 'LineWidth', 1.5); % Cor vermelha para diferenciar
148+
subplot(2, 1, 2);
149+
plot(x, M, 'LineWidth', 1.5, 'Color', 'r'); % Red color to differentiate
179150
hold on;
180151
plot(x, y, 'k--');
181152
grid on;
153+
box on;
182154
title('Bending Moment Diagram');
183155
ylabel('Bending Moment (Nm)');
184156
xlabel('Position (x)');
185157
fill([x, fliplr(x)], [M, fliplr(y)], 'r', 'FaceAlpha', 0.3, 'EdgeColor', 'none');
158+
xlim([min(x) max(x)]);
159+
ylim([min(M) max(M)]);
186160
hold off;

0 commit comments

Comments
 (0)