#ifndef RTS_PLANEWAVE #define RTS_PLANEWAVE #include #include #include "../math/vector.h" #include "../math/quaternion.h" #include "../math/constants.h" /*Basic conversions used here (assuming a vacuum) lambda = */ namespace rts{ template class planewave{ public: vec

k; //k = tau / lambda vec

E0; //amplitude ///constructor: create a plane wave propagating along z, polarized along x /*planewave(P lambda = (P)1) { k = rts::vec

(0, 0, 1) * (TAU/lambda); E0 = rts::vec

(1, 0, 0); }*/ ///constructor: create a plane wave propagating along _k, polarized along _E0, at frequency _omega planewave(vec

_k = rts::vec

(0, 0, TAU), vec

_E0 = rts::vec

(1, 0, 0)) { k = _k; vec

k_hat = _k.norm(); vec

s = (k.cross(_E0)).norm(); //compute an orthogonal side vector vec

E0_hat = (s.cross(k)).norm(); //compute a normalized E0 direction vector E0 = E0_hat * E0_hat.dot(_E0); //compute the projection of _E0 onto E0_hat } ///multiplication operator: scale E0 planewave

& operator* (const P & rhs) { E0 = E0 * rhs; return *this; } P lambda() const { return TAU / k.len(); } P kmag() const { return k.len(); } planewave

refract(rts::vec

kn) const { vec

kn_hat = kn.norm(); //normalize the new k vec

k_hat = k.norm(); //normalize the current k vec

r = k_hat.cross(kn_hat); //compute the rotation vector P theta = asin(r.len()); //compute the angle of the rotation about r planewave

new_p; //create a new plane wave //deal with a zero vector (both k and kn point in the same direction) if(theta == (P)0) { new_p = *this; return new_p; } //create a quaternion to capture the rotation quaternion

q; q.CreateRotation(theta, r.norm()); //apply the rotation to E0 vec

E0n = q.toMatrix3() * E0; new_p.k = kn_hat * k.len(); new_p.E0 = E0n; return new_p; /*vec

kn_hat = kn.norm(); //normalize new_k vec

k_hat = k.norm(); //compute the side vector (around which we will be rotating) vec

E0_hat = E0.norm(); rts::vec

s = k_hat.cross(E0_hat); //compute the projection of k' onto the k-E plane rts::vec

s_prime = s * (kn_hat.dot(s)); //compute the angle between vec

kp_hat = (kn_hat - s_prime).norm(); P theta = acos(k_hat.dot( kp_hat )); if(kn_hat.dot(E0_hat) < 0) theta = -theta; //rotate E0 around s by theta quaternion

q; q.CreateRotation(theta, s); rts::vec

E0_prime = q.toMatrix3() * E0; //create the refracted plane wave planewave

new_p; new_p.E0 = E0_prime; new_p.k = kn_hat * k.len(); return new_p;*/ /*vec

kn_hat = kn.norm(); //normalize kn vec

k_hat = k.norm(); vec

E0_hat = E0.norm(); vec

B = k_hat.cross(E0_hat); planewave

newp; newp.k = kn_hat * k.len(); newp.E0 = B.cross(kn_hat).norm(); std::cout< s_hat = k_hat.cross(E0_hat); //std::cout< sp = s_hat * (kn_hat.dot(s_hat)); //project k_new onto s rts::vec

kp = (kn_hat - sp); //correct k_new so it lies on the E0-k plane rts::vec

kp_hat = kp.norm(); //compute the angle and direction between k_prime and k P theta = acos(k_hat.dot(kp_hat)); if(kp_hat.dot(E0_hat) < 0) theta = -theta; //rotate E0 around s by theta quaternion

q; q.CreateRotation(theta, s_hat); rts::vec

E0n = q.toMatrix3() * E0; rts::vec

E0n_hat = E0n.norm(); //std::cout< new_p(kn_hat * k.len(), E0n); //create the plane wave std::cout<<"|E0n|: "<