Blame view

planewave.h 1.2 KB
3f36b18e   David Mayerich   Adding planewave ...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
  #ifndef __PLANEWAVE__
  #define __PLANEWAVE__
  
  #include <iostream>
  #include <sstream>
  
  #include "rts/math/vector.h"
  
  template<class T>
  class planewave
  {
      rts::vector<T, 3> k;
      rts::vector<T, 3> E;
  
      public:
  
      //constructor, initialize to an x-polarized wave propagating along z
      planewave()
      {
          k = rts::vector<T, 3>(0, 0, 1);
          E = rts::vector<T, 3>(1, 0, 0);
      }
  
      planewave(rts::vector<T, 3> k_vec, rts::vector<T, 3> E0)
      {
          k = k_vec;
  
          //enforce k \dot E = 0
          rts::vector<T, 3> s = E0.cross(k);
          rts::vector<T, 3> E_hat;
  
          if(s.len() == 0)
              E_hat = rts::vector<T, 3>(0, 0, 0);
          else
              E_hat = (s.cross(k)).norm();
  
          E = E_hat * (E_hat.dot(E0));
      }
  
      // refract will bend the wave vector k to correspond to the normalized vector v
396a5f12   David Mayerich   added custom code...
41
      void refract(rts::vector<T, 3> v)
3f36b18e   David Mayerich   Adding planewave ...
42
43
44
45
46
47
48
      {
          //make sure that v is normalized
          v = v.norm();
  
  
      }
  
396a5f12   David Mayerich   added custom code...
49
50
51
52
      std::string toStr()
  	{
  		std::stringstream ss;
  
3f36b18e   David Mayerich   Adding planewave ...
53
  		ss<<"k = "<<k<<std::endl;
396a5f12   David Mayerich   added custom code...
54
55
56
  		ss<<"E = "<<E<<std::endl;
  
  		return ss.str();
3f36b18e   David Mayerich   Adding planewave ...
57
58
59
60
61
62
  	}
  
  
  
  };
  
396a5f12   David Mayerich   added custom code...
63
64
65
66
67
  template <typename T>
  std::ostream& operator<<(std::ostream& os, planewave<T> p)
  {
      os<<p.toStr();
      return os;
3f36b18e   David Mayerich   Adding planewave ...
68
69
70
71
72
  }
  
  
  
  #endif