function treillis_bois_gui()
% Création de la fenêtre principale
fig = uifigure('Name', 'Dimensionnement Treillis en Bois', ...
'Position', [100 100 400 450]);
% Titre
uilabel(fig, 'Position', [20 400 360 30], ...
'Text', 'DIMENSIONNEMENT TREILLIS EN BOIS', ...
'FontSize', 16, 'FontWeight', 'bold', ...
'HorizontalAlignment', 'center');
% ==================== CHAMPS DE SAISIE ====================
y_pos = 350;
% Longueur L
uilabel(fig, 'Position', [20 y_pos 150 22], 'Text', 'Longueur L (m):');
edit_L = uieditfield(fig, 'numeric', ...
'Position', [180 y_pos 100 22], ...
'Value', 1.0);
y_pos = y_pos - 35;
% Module d'Young E
uilabel(fig, 'Position', [20 y_pos 150 22], 'Text', 'Module E (Pa):');
edit_E = uieditfield(fig, 'numeric', ...
'Position', [180 y_pos 100 22], ...
'Value', 10e9);
y_pos = y_pos - 35;
% Section A
uilabel(fig, 'Position', [20 y_pos 150 22], 'Text', 'Section A (m²):');
edit_A = uieditfield(fig, 'numeric', ...
'Position', [180 y_pos 100 22], ...
'Value', 0.01);
y_pos = y_pos - 35;
% Force F
uilabel(fig, 'Position', [20 y_pos 150 22], 'Text', 'Force F (N):');
edit_F = uieditfield(fig, 'numeric', ...
'Position', [180 y_pos 100 22], ...
'Value', 1000);
y_pos = y_pos - 35;
% ==================== BOUTON DIMENSIONNER ====================
uibutton(fig, 'push', ...
'Position', [150 y_pos-10 100 30], ...
'Text', 'DIMENSIONNER', ...
'FontWeight', 'bold', ...
'ButtonPushedFcn', @(btn,event) calculer_treillis());
% Zone d'information
info_label = uilabel(fig, 'Position', [50 y_pos-50 300 30], ...
'Text', 'Cliquez sur "DIMENSIONNER" pour lancer le calcul', ...
'FontSize', 11, ...
'HorizontalAlignment', 'center');
% ==================== FONCTION DE CALCUL TREILLIS ====================
function calculer_treillis()
% Récupération des valeurs
L = edit_L.Value;
E = edit_E.Value;
A = edit_A.Value;
F_val = edit_F.Value;
% Validation
if L <= 0 || E <= 0 || A <= 0 || F_val <= 0
info_label.Text = 'ERREUR: Toutes les valeurs doivent être > 0';
info_label.FontColor = 'red';
return;
end
info_label.Text = 'Calcul en cours...';
info_label.FontColor = 'blue';
drawnow;
try
% ==================== GÉOMÉTRIE ====================
H = (2/3)*L;
% Coordonnées des nœuds
coords = [
0, 0; % Nœud 1
0, H; % Nœud 2
L, H; % Nœud 3
L, 0; % Nœud 4
2*L, 0; % Nœud 5
2*L, H; % Nœud 6
3*L, H; % Nœud 7
3*L, 0; % Nœud 8
4*L, H; % Nœud 9
4*L, 0 % Nœud 10
];
% Connectivité des barres (treillis)
elements = [
1, 2; 2, 3; 3, 4; 4, 1; 1, 3;
4, 5; 5, 6; 6, 3; 3, 5;
5, 8; 8, 7; 7, 6; 5, 7;
8, 10; 10, 9; 9, 7; 7, 10
];
% ==================== INITIALISATION ====================
n_nodes = size(coords, 1);
n_elems = size(elements, 1);
dof = 2 * n_nodes; % 20 DOF (seulement translations)
K_global = zeros(dof);
F_global = zeros(dof, 1);
% ==================== CHARGEMENT ====================
F_global(2*4) = F_global(2*4) - F_val; % Nœud 4
F_global(2*5) = F_global(2*5) - 2*F_val; % Nœud 5
F_global(2*8) = F_global(2*8) - F_val; % Nœud 8
% ==================== ASSEMBLAGE MATRICE RIGIDITÉ ====================
for i = 1:n_elems
n1 = elements(i, 1);
n2 = elements(i, 2);
x1 = coords(n1, 1); y1 = coords(n1, 2);
x2 = coords(n2, 1); y2 = coords(n2, 2);
L_elem = sqrt((x2 - x1)^2 + (y2 - y1)^2);
c = (x2 - x1) / L_elem;
s = (y2 - y1) / L_elem;
% Matrice de rigidité élémentaire TREILLIS (4 DOF)
k_local = (E * A / L_elem) * [c^2, c*s, -c^2, -c*s;
c*s, s^2, -c*s, -s^2;
-c^2, -c*s, c^2, c*s;
-c*s, -s^2, c*s, s^2];
% Degrés de liberté globaux
dofs = [2*n1-1, 2*n1, 2*n2-1, 2*n2];
% Assemblage
K_global(dofs, dofs) = K_global(dofs, dofs) + k_local;
end
% ==================== CONDITIONS AUX LIMITES ====================
% Nœud 1: appui double
fixed_dofs = [2*1-1, 2*1];
% Nœud 10: appui simple
fixed_dofs = [fixed_dofs, 2*10];
free_dofs = setdiff(1:dof, fixed_dofs);
% ==================== RÉSOLUTION ====================
K_red = K_global(free_dofs, free_dofs);
F_red = F_global(free_dofs);
U_red = K_red \ F_red;
U = zeros(dof, 1);
U(free_dofs) = U_red;
R = K_global * U - F_global;
% ==================== AFFICHAGE RÉSULTATS ====================
fprintf('\n=== RÉSULTATS DU TREILLIS ===\n');
fprintf('Paramètres: L=%.2f m, E=%.2e Pa, A=%.4f m², F=%.0f N\n', ...
L, E, A, F_val);
fprintf('\n--- DÉPLACEMENTS AUX NŒUDS ---\n');
for i = 1:n_nodes
fprintf('Nœud %2d: ux = %12.6e m, uy = %12.6e m\n', ...
i, U(2*i-1), U(2*i));
end
fprintf('\n--- RÉACTIONS AUX APPUIS ---\n');
fprintf('Nœud 1: Rx = %12.6e N, Ry = %12.6e N\n', R(1), R(2));
fprintf('Nœud 10: Ry = %12.6e N\n', R(20));
% Vérification équilibre
sum_Fy = F_val + 2*F_val + F_val + R(2) + R(20);
fprintf('\n--- VÉRIFICATION ÉQUILIBRE ---\n');
fprintf('ΣFy = %.6f N (devrait être 0)\n', sum_Fy);
% ==================== VISUALISATION ====================
figure('Name', 'Résultats du Treillis');
hold on; axis equal; grid on;
title('Treillis en Bois - Déplacements et Réactions');
% Tracé des barres
for i = 1:n_elems
n1 = elements(i, 1);
n2 = elements(i, 2);
plot([coords(n1,1), coords(n2,1)], [coords(n1,2), coords(n2,2)], ...
'b-', 'LineWidth', 2);
end
% Nœuds
plot(coords(:,1), coords(:,2), 'bo', 'MarkerSize', 6, 'MarkerFaceColor', 'b');
% Charges
arrow_scale = 0.1 * L;
load_nodes = [4, 5, 8];
for i = 1:length(load_nodes)
node = load_nodes(i);
x = coords(node, 1); y = coords(node, 2);
quiver(x, y, 0, -arrow_scale, 0, 'm', 'LineWidth', 2, 'MaxHeadSize', 0.5);
if node == 5
label = '2F';
else
label = 'F';
end
text(x, y-0.15, label, 'Color', 'm', 'FontWeight', 'bold', 'HorizontalAlignment',
'center');
end
% Réactions
Rx1 = R(1); Ry1 = R(2); Ry10 = R(20);
if abs(Rx1) > 1e-6
quiver(coords(1,1), coords(1,2), sign(Rx1)*arrow_scale, 0, 0, 'g', 'LineWidth', 2,
'MaxHeadSize', 0.5);
end
if abs(Ry1) > 1e-6
quiver(coords(1,1), coords(1,2), 0, sign(Ry1)*arrow_scale, 0, 'g', 'LineWidth', 2,
'MaxHeadSize', 0.5);
end
if abs(Ry10) > 1e-6
quiver(coords(10,1), coords(10,2), 0, sign(Ry10)*arrow_scale, 0, 'y', 'LineWidth', 2,
'MaxHeadSize', 0.5);
end
% Textes réactions
text(coords(1,1), coords(1,2)-0.2, sprintf('R_x=%.0f N\nR_y=%.0f N', Rx1, Ry1), ...
'Color', 'g', 'FontSize', 8, 'HorizontalAlignment', 'center', 'BackgroundColor', 'white');
text(coords(10,1), coords(10,2)-0.2, sprintf('R_y=%.0f N', Ry10), ...
'Color', 'y', 'FontSize', 8, 'HorizontalAlignment', 'center', 'BackgroundColor', 'white');
xlabel('X (m)'); ylabel('Y (m)');
info_label.Text = 'Calcul TREILLIS terminé avec succès!';
info_label.FontColor = 'green';
catch ME
info_label.Text = 'ERREUR lors du calcul';
info_label.FontColor = 'red';
fprintf('Erreur: %s\n', ME.message);
end
end
end