rl_basicray  1.0.12
rl_BasicRay.cc
1 // File: rl_BasicRay.cc
2 // Author: Terry Gaetz
3 //
4 // --8<--8<--8<--8<--
5 //
6 // Copyright (C) 2006 Smithsonian Astrophysical Observatory
7 //
8 // This file is part of rl_ray
9 //
10 // rl_ray is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU General Public License
12 // as published by the Free Software Foundation; either version 2
13 // of the License, or (at your option) any later version.
14 //
15 // rl_ray is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the
22 // Free Software Foundation, Inc.
23 // 51 Franklin Street, Fifth Floor
24 // Boston, MA 02110-1301, USA
25 //
26 // -->8-->8-->8-->8--
27 
28 #include <rl_basicray/rl_BasicRay.h>
29 
30 #include <iostream>
31 #include <sstream>
32 #include <iomanip>
33 
34 using namespace std;
35 
36 //=========================================================================
37 // dtor, ctors, initializers...
38 
39 //-------------------------------------------------------------------------
42 {}
43 
44 //=========================================================================
45 // mutators...
46 
47 //=========================================================================
48 // ray reflection...
49 
50 //-------------------------------------------------------------------------
51 double rl_BasicRay::
52 reflect_direction_vector( dvm3_Vector const& normal )
53 {
54  // calculate sine of the grazing angle
55  double sg = dot( dir_, normal );
56 
57  // reflect the direction vector:
58  // vo = (1 - 2 norm <diadprod> norm) <dotprod> vi
59 
60  dir_.lincomb( 1.0, dir_, -2.0 * sg, normal );
61 
62  return sg;
63 }
64 
65 //=========================================================================
66 // I/O...
67 
68 //-------------------------------------------------------------------------
69 ostream& rl_BasicRay::
70 print_on( ostream& os, char const prefix[], char const postfix[] ) const
71 {
72  os.setf( ios::scientific, ios::floatfield );
73  os.precision(15);
74  if ( ::strlen(prefix) ) { os << prefix; }
75  os << id_ << ": " << energy_ << " " << pos_ << " " << dir_;
76  if ( ::strlen(postfix) ) { os << postfix; }
77  return os;
78 }
79 
80 //-------------------------------------------------------------------------
81 ostream&
82 operator<<( ostream& os, rl_BasicRay const& r )
83 {
84  return r.print_on( os, "ray[", "]" );
85 }
std::ostream & print_on(std::ostream &os, char const prefix[]="", char const postfix[]="") const
Print the ray properties to an output stream.
Definition: rl_BasicRay.cc:70
A basic ray: encapsulates position and direction vectors, energy, and ray id.
Definition: rl_BasicRay.h:47
double reflect_direction_vector(dvm3_Vector const &normal)
Reflect this ray's direction vector about a (surface) normal.
Definition: rl_BasicRay.cc:52
virtual ~rl_BasicRay()
A virtual do-nothing destructor.
Definition: rl_BasicRay.cc:41