Guest User

Untitled

a guest
Nov 20th, 2025
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.03 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. from numpy.linalg import norm
  4. from numpy import dot
  5.  
  6. def scatter(k0, g, n):
  7.     # assumes k_incident is in the -z direction
  8.     # k0 is the scalar incident wave vector (magnitude)
  9.     # g is a reciprocal vector of the diffractive surface
  10.     # n is the normal vector to that surface
  11.    
  12.     z_hat = np.array([0, 0, 1])
  13.  
  14.     k0_perp = -k0 * n * dot(z_hat, n)
  15.  
  16.     # k0_par = -k0 * z_hat + k0 * n * dot(z_hat, n)
  17.     # k0_par = k0 * (n * dot(z_hat, n) - z_hat)
  18.     # k1_par = k0_par + g
  19.  
  20.     k1_par = k0 * (n * dot(z_hat, n) - z_hat) + g
  21.  
  22.     k1_perp = (k0**2 - norm(k1_par)**2)**0.5 * n
  23.  
  24.     k1 = k1_par + k1_perp
  25.  
  26.     return k1
  27.  
  28.  
  29. k0 = 10.
  30. n = np.array([1, 0, 1]) / 2**0.5
  31. g = 3. * np.array([0, 1, 0])
  32.  
  33. k1 = scatter(k0, g, n)
  34.  
  35. print('k0: ', k0)
  36. print('n: ', n)
  37. print('g: ', g)
  38. print('')
  39.  
  40. print('check perpendicularity, g dot n: ', dot(g, n))
  41. print('')
  42.  
  43. print('k1: ', k1)
  44. print('')
  45.  
  46. print('check conservation of energy norm(k1) = k0: ', norm(k1), k0)
  47.  
  48.  
  49.  
Advertisement
Add Comment
Please, Sign In to add comment