# -*- coding: utf-8 -*-
"""
Created on Wed Apr  1 03:05:16 2026

@author: pjaub
"""

import numpy as np
import matplotlib.pyplot as plt

plt.close('all')

# --------------------------------------------------
# 1) Définition de la surface
# --------------------------------------------------


def f(x, y):
    return (3*(x**2+y**2)*np.exp(-(x-1)**2-(y-1)**2) - 
                2*np.exp(-(x+1.5)**2-(y+1)**2) + 0.3*(x**2 - y**2))

def f(x, y):
    return (3*(x**2+y**2))

def f(x, y):
    return (3*(x**2+y**2))*(x>0)


def f(x, y):
    return (3*(x**2-2*y**2))*(x>0) + (3*(-x**2+y**2))*(x<0)


def f(x, y):
    return 1/np.pi*np.exp(-(x**2+y**2)/2)

def f(x, y):
    return (3*np.exp(-(x-1)**2-(y-1)**2) - 
                2*np.exp(-(x+1.5)**2-(y+1)**2) + 0.3*(x**2 - y**2))

def f(x, y):
    return (
        2*np.sin(x)*np.cos(y)
        + 0.5*np.cos(2*x)
        - 0.7*np.sin(2*y)
    )

# --------------------------------------------------
# 2) Grille de points
# --------------------------------------------------
x = np.linspace(-4, 4, 300)
y = np.linspace(-4, 4, 300)
X, Y = np.meshgrid(x, y)
Z = f(X, Y)

# --------------------------------------------------
# 3) Figure avec surface + lignes de niveau
# --------------------------------------------------
fig = plt.figure(figsize=(12, 5))

# ---- Surface 3D
ax1 = fig.add_subplot(1, 2, 1, projection='3d')
surf = ax1.plot_surface(X, Y, Z, cmap='viridis', edgecolor='none')
ax1.set_title("Surface dans l'espace")
ax1.set_xlabel("x")
ax1.set_ylabel("y")
ax1.set_zlabel("z")

# On ajoute les lignes de niveau projetées en bas
ax1.contour(X, Y, Z, levels=15, zdir='z', offset=Z.min()-0.5, cmap='plasma')
ax1.set_zlim(Z.min()-0.5, Z.max())

# ---- Lignes de niveau dans le plan
ax2 = fig.add_subplot(1, 2, 2)
contours = ax2.contour(X, Y, Z, levels=15, cmap='plasma')
ax2.clabel(contours, inline=True, fontsize=8)
ax2.set_title("Lignes de niveau")
ax2.set_xlabel("x")
ax2.set_ylabel("y")
ax2.set_aspect('equal')

plt.tight_layout()
plt.show()

