# -*- coding: utf-8 -*-
"""
Created on Wed Apr  1 03:24:22 2026

@author: pjaub
"""

import numpy as np
import matplotlib.pyplot as plt

plt.close('all')


# rayon maximal correspondant à z = 20
rmax = np.sqrt(20)

# grille
x = np.linspace(-rmax, rmax, 300)
y = np.linspace(-rmax, rmax, 300)
X, Y = np.meshgrid(x, y)

# paraboloïde
Z = X**2 + Y**2

# masque : on ne garde que la zone z <= 20
Z = np.where(Z <= 20, Z, np.nan)

# figure 3D
fig = plt.figure(figsize=(10, 8))
ax = fig.add_subplot(111, projection='3d')

# surface
ax.plot_surface(X, Y, Z, cmap='viridis', edgecolor='none', alpha=0.85)

# courbes de niveau projetées dans le plan z = 0
ax.contour(X, Y, np.nan_to_num(Z, nan=20), levels=15, zdir='z', offset=0, cmap='plasma')



# réglages
ax.set_title("Paraboloïde de révolution tronqué à z = 20")
ax.set_xlabel("x")
ax.set_ylabel("y")
ax.set_zlabel("z")
ax.set_zlim(0, 22)

plt.tight_layout()
plt.show()