import numpy as np
import matplotlib.pyplot as plt
def plot_ship_2d_sections_vertical():
# Paramètres du navire
L = 100 # Longueur (X)
B = 20 # Largeur (Y)
D = 12 # Tirant d'eau (Z)
# Création d'une figure avec 3 sous-graphiques empilés verticalement
# On augmente la hauteur de la figure pour maintenir un aspect proportionnel
fig, axes = plt.subplots(3, 1, figsize=(8, 18), facecolor='#f8f9fa')
# --- PANEL 1: COUPE TRANSVERSALE (PLAN Y-Z) ---
ax = axes[0]
z_vals = np.linspace(0, D, 100)
# Profil parabolique : y = +/- (B/2) * sqrt(z/D)
y_left = -(B/2) * np.sqrt(z_vals/D)
y_right = (B/2) * np.sqrt(z_vals/D)
ax.fill(np.concatenate([y_left, y_right[::-1]]),
np.concatenate([z_vals, z_vals[::-1]]),
color='skyblue', alpha=0.5, label='Coque')
ax.plot(y_left, z_vals, 'b-', linewidth=2)
ax.plot(y_right, z_vals, 'b-', linewidth=2)
# Axes (Origine à la quille centrale)
ax.quiver(0, 0, B/4, 0, color='green', scale=1, units='xy', label='y (Trans)')
ax.quiver(0, 0, 0, D/2, color='blue', scale=1, units='xy', label='z (Vert)')
ax.set_title("Coupe Transversale (X=0)", fontsize=14, pad=15)
ax.set_xlabel("x (Transversal)")
ax.set_ylabel("z (Vertical)")
ax.set_aspect('equal')
ax.grid(True, linestyle='--', alpha=0.6)
ax.legend(loc='upper right', fontsize='small')
# --- PANEL 2: COUPE LONGITUDINALE (PLAN X-Z) ---
ax = axes[1]
z_vals = np.linspace(0, D, 100)
# Profil parabolique : x = +/- (L/2) * sqrt(z/D)
x_left = -(L/2) * np.sqrt(z_vals/D)
x_right = (L/2) * np.sqrt(z_vals/D)
ax.fill(np.concatenate([x_left, x_right[::-1]]),
np.concatenate([z_vals, z_vals[::-1]]),
color='lightcoral', alpha=0.5, label='Coque')
ax.plot(x_left, z_vals, 'r-', linewidth=2)
ax.plot(x_right, z_vals, 'r-', linewidth=2)
# Axes (Origine à la quille centrale)
ax.quiver(0, 0, L/4, 0, color='red', scale=1, units='xy', label='x (Long)')
ax.quiver(0, 0, 0, D/2, color='blue', scale=1, units='xy', label='z (Vert)')
ax.set_title("Coupe Longitudinale (Y=0)", fontsize=14, pad=15)
ax.set_xlabel("x (Longitudinal)")
ax.set_ylabel("z (Vertical)")
ax.set_aspect('equal')
ax.grid(True, linestyle='--', alpha=0.6)
ax.legend(loc='upper right', fontsize='small')
# --- PANEL 3: COUPE HORIZONTALE / PLAN (PLAN X-Y) ---
ax = axes[2]
# Vue de dessus à la ligne de flottaison (Z=D)
theta = np.linspace(0, 2*np.pi, 100)
x_ellipse = (L/2) * np.cos(theta)
y_ellipse = (B/2) * np.sin(theta)
ax.fill(x_ellipse, y_ellipse, color='gray', alpha=0.3, label='Empreinte')
ax.plot(x_ellipse, y_ellipse, 'k-', linewidth=2)
# Axes (Origine au centre géométrique)
ax.quiver(0, 0, L/4, 0, color='red', scale=1, units='xy', label='y (Long)')
ax.quiver(0, 0, 0, B/4, color='green', scale=1, units='xy', label='x (Trans)')
ax.set_title("Coupe Horizontale (Plan)", fontsize=14, pad=15)
ax.set_xlabel("x (Longitudinal)")
ax.set_ylabel("y (Transversal)")
ax.set_aspect('equal')
ax.grid(True, linestyle='--', alpha=0.6)
ax.legend(loc='upper right', fontsize='small')
plt.tight_layout()
plt.show()
if __name__ == "__main__":
plot_ship_2d_sections_vertical()