00001 // File: rl_BasicRay.cc 00002 // Author: Terry Gaetz 00003 // 00004 // --8<--8<--8<--8<-- 00005 // 00006 // Copyright (C) 2006 Smithsonian Astrophysical Observatory 00007 // 00008 // This file is part of rl_ray 00009 // 00010 // rl_ray is free software; you can redistribute it and/or 00011 // modify it under the terms of the GNU General Public License 00012 // as published by the Free Software Foundation; either version 2 00013 // of the License, or (at your option) any later version. 00014 // 00015 // rl_ray is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 // GNU General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU General Public License 00021 // along with this program; if not, write to the 00022 // Free Software Foundation, Inc. 00023 // 51 Franklin Street, Fifth Floor 00024 // Boston, MA 02110-1301, USA 00025 // 00026 // -->8-->8-->8-->8-- 00027 00028 #include <rl_basicray/rl_BasicRay.h> 00029 00030 #include <iostream> 00031 #include <sstream> 00032 #include <iomanip> 00033 00034 using namespace std; 00035 00036 //========================================================================= 00037 // dtor, ctors, initializers... 00038 00039 //------------------------------------------------------------------------- 00040 rl_BasicRay:: 00041 ~rl_BasicRay() 00042 {} 00043 00044 //========================================================================= 00045 // mutators... 00046 00047 //========================================================================= 00048 // ray reflection... 00049 00050 //------------------------------------------------------------------------- 00051 double rl_BasicRay:: 00052 reflect_direction_vector( dvm3_Vector const& normal ) 00053 { 00054 // calculate sine of the grazing angle 00055 double sg = dot( dir_, normal ); 00056 00057 // reflect the direction vector: 00058 // vo = (1 - 2 norm <diadprod> norm) <dotprod> vi 00059 00060 dir_.lincomb( 1.0, dir_, -2.0 * sg, normal ); 00061 00062 return sg; 00063 } 00064 00065 //========================================================================= 00066 // I/O... 00067 00068 //------------------------------------------------------------------------- 00069 ostream& rl_BasicRay:: 00070 print_on( ostream& os, char const prefix[], char const postfix[] ) const 00071 { 00072 os.setf( ios::scientific, ios::floatfield ); 00073 os.precision(15); 00074 if ( ::strlen(prefix) ) { os << prefix; } 00075 os << id_ << ": " << energy_ << " " << pos_ << " " << dir_; 00076 if ( ::strlen(postfix) ) { os << postfix; } 00077 return os; 00078 } 00079 00080 //------------------------------------------------------------------------- 00081 ostream& 00082 operator<<( ostream& os, rl_BasicRay const& r ) 00083 { 00084 return r.print_on( os, "ray[", "]" ); 00085 }