Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MVec.hpp
Go to the documentation of this file.
1 #ifndef MVEC_H
2 #define MVEC_H
3 
4 #include <iostream.h>
5 #include <math.h>
6 #include "general.hpp"
7 
8 class MVec {
9 public:
10 
11  MVec();
12  MVec( const MVec& v);
13  MVec( double x, double y, double z );
14 
15  ~MVec();
16 
17  friend istream& operator>>(istream& stream, MVec& v);
18 
19  friend ostream& operator<<(ostream& stream, const MVec& v);
20 
21  MVec operator-(const MVec& ovec) const;
22  MVec operator+(const MVec& ovec) const;
23  MVec operator/(double val) const;
24  MVec operator*(double val) const;
25 
26  const MVec& operator=( const MVec ovec);
27 
28  // compare - within epsilon range
29  boolean operator==( const MVec ovec) const;
30 
31  // cross product
32  MVec operator*(const MVec& ovec) const;
33 
34  // scalar product
35  double operator%(const MVec& ovec) const;
36 
37  double length() const;
38  double length_squared() const;
39  double distance_between(MVec & end) const;
40 
41  void normalize();
42 
43  double x() const;
44  double y() const;
45  double z() const;
46 
47  void x(double nx);
48  void y(double ny);
49  void z(double nz);
50 
51  double operator[](int i) const;
52 
53  void move_to_line( const MVec& from, const MVec& to );
54 
55 private:
56 
57  double d_x;
58  double d_y;
59  double d_z;
60 
61 };
62 
63 const double c_epsilon = 1e-5;
64 const double c_epsilon2 = c_epsilon * c_epsilon;
66 
67 inline const MVec& MVec::operator=( const MVec ovec){
68 
69  d_x = ovec.d_x;
70  d_y = ovec.d_y;
71  d_z = ovec.d_z;
72  return *this;
73 }
74 
75 // scalar product
76 inline double MVec::operator%(const MVec& ovec) const {
77 
78  return d_x * ovec.d_x + d_y * ovec.d_y + d_z * ovec.d_z;
79 }
80 
81 
82 inline double MVec::length() const {
83  return sqrt( d_x * d_x + d_y * d_y + d_z * d_z);
84 }
85 
86 inline double MVec::length_squared() const {
87  return d_x * d_x + d_y * d_y + d_z * d_z;
88 }
89 
90 inline double MVec::distance_between(MVec & end) const {
91  return sqrt( pow((d_x - end.x()),2) +
92  pow((d_y - end.y()),2) +
93  pow((d_z - end.z()),2) ) ;
94 }
95 
96 inline void MVec::normalize(){
97  double len = length();
98 
99  d_x /= len;
100  d_y /= len;
101  d_z /= len;
102 }
103 
104 inline double MVec::x() const { return d_x; }
105 inline double MVec::y() const { return d_y; }
106 inline double MVec::z() const { return d_z; }
107 
108 inline void MVec::x(double nx) { d_x = nx; }
109 inline void MVec::y(double ny) { d_y = ny; }
110 inline void MVec::z(double nz) { d_z = nz; }
111 
112 inline double MVec::operator[](int i) const{
113  return ( i == 0 ? d_x : ( i == 1 ? d_y : d_z ) );
114 }
115 
116 #endif
117 
118 
119 
double x() const
Definition: MVec.hpp:104
double operator%(const MVec &ovec) const
Definition: MVec.hpp:76
void normalize()
Definition: MVec.hpp:96
Definition: MVec.hpp:8
const MVec c_vec_epsilon(c_epsilon, c_epsilon, c_epsilon)
double sqrt(double d)
Definition: double.h:73
double z() const
Definition: MVec.hpp:106
*********************************************************************Illinois Open Source License ****University of Illinois NCSA **Open Source License University of Illinois All rights reserved ****Developed free of to any person **obtaining a copy of this software and associated documentation to deal with the Software without including without limitation the rights to and or **sell copies of the and to permit persons to whom the **Software is furnished to do subject to the following this list of conditions and the following disclaimers ****Redistributions in binary form must reproduce the above **copyright this list of conditions and the following **disclaimers in the documentation and or other materials **provided with the distribution ****Neither the names of the Center for Simulation of Advanced the University of nor the names of its **contributors may be used to endorse or promote products derived **from this Software without specific prior written permission ****THE SOFTWARE IS PROVIDED AS WITHOUT WARRANTY OF ANY **EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES **OF FITNESS FOR A PARTICULAR PURPOSE AND **NONINFRINGEMENT IN NO EVENT SHALL THE CONTRIBUTORS OR **COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN AN ACTION OF TORT OR **ARISING OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE **USE OR OTHER DEALINGS WITH THE SOFTWARE v
Definition: roccomf90.h:20
MVec()
Definition: MVec.cpp:5
MVec operator-(const MVec &ovec) const
Definition: MVec.cpp:30
friend ostream & operator<<(ostream &stream, const MVec &v)
Definition: MVec.cpp:25
friend istream & operator>>(istream &stream, MVec &v)
Definition: MVec.cpp:19
double length_squared() const
Definition: MVec.hpp:86
double length() const
Definition: MVec.hpp:82
blockLoc i
Definition: read.cpp:79
const double c_epsilon
Definition: MVec.hpp:63
boolean operator==(const MVec ovec) const
Definition: MVec.cpp:76
double d_z
Definition: MVec.hpp:59
MVec operator/(double val) const
Definition: MVec.cpp:48
void move_to_line(const MVec &from, const MVec &to)
Definition: MVec.cpp:90
double d_x
Definition: MVec.hpp:57
~MVec()
Definition: MVec.cpp:16
double y() const
Definition: MVec.hpp:105
const MVec & operator=(const MVec ovec)
Definition: MVec.hpp:67
MVec operator*(double val) const
Definition: MVec.cpp:57
MVec operator+(const MVec &ovec) const
Definition: MVec.cpp:39
double pow(double value, const Exponent &exp)
double distance_between(MVec &end) const
Definition: MVec.hpp:90
const double c_epsilon2
Definition: MVec.hpp:64
double operator[](int i) const
Definition: MVec.hpp:112
double d_y
Definition: MVec.hpp:58