Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MVec.cpp
Go to the documentation of this file.
1 
2 #include "MVec.hpp"
3 #include <math.h>
4 
6 MVec::MVec( const MVec& v) :
7  d_x(v.d_x),
8  d_y(v.d_y),
9  d_z(v.d_z) {}
10 
11 MVec::MVec( double x, double y, double z ) :
12  d_x(x),
13  d_y(y),
14  d_z(z) {}
15 
17 
18 
19 istream& operator>>(istream& stream, MVec& v) {
20  stream >> v.d_x >> v.d_y >> v.d_z;
21  return stream;
22 }
23 
24 
25 ostream& operator<<(ostream& stream, const MVec& v) {
26  stream << ' ' << v.d_x << ' ' << v.d_y << ' ' << v.d_z;
27  return stream;
28 }
29 
30 MVec MVec::operator-(const MVec& ovec) const{
31 
32  MVec v;
33  v.d_x = d_x - ovec.d_x;
34  v.d_y = d_y - ovec.d_y;
35  v.d_z = d_z - ovec.d_z;
36  return v;
37 }
38 
39 MVec MVec::operator+(const MVec& ovec) const {
40 
41  MVec v;
42  v.d_x = d_x + ovec.d_x;
43  v.d_y = d_y + ovec.d_y;
44  v.d_z = d_z + ovec.d_z;
45  return v;
46 }
47 
48 MVec MVec::operator/(double val) const{
49 
50  MVec v;
51  v.d_x = d_x/val;
52  v.d_y = d_y/val;
53  v.d_z = d_z/val;
54  return v;
55 }
56 
57 MVec MVec::operator*(double val) const{
58 
59  MVec v;
60  v.d_x = d_x*val;
61  v.d_y = d_y*val;
62  v.d_z = d_z*val;
63  return v;
64 }
65 
66 // cross product
67 MVec MVec::operator*(const MVec& ovec) const {
68 
69  MVec v;
70  v.d_x = d_y * ovec.d_z - d_z * ovec.d_y;
71  v.d_y = d_z * ovec.d_x - d_x * ovec.d_z;
72  v.d_z = d_x * ovec.d_y - d_y * ovec.d_x;
73  return v;
74 }
75 
76 boolean MVec::operator==( const MVec ovec) const {
77 
78  if( ovec.d_x > d_x + c_epsilon
79  || ovec.d_x < d_x - c_epsilon
80  || ovec.d_y > d_y + c_epsilon
81  || ovec.d_y < d_y - c_epsilon
82  || ovec.d_z > d_z + c_epsilon
83  || ovec.d_z < d_z - c_epsilon ) {
84  return FALSE;
85  }
86  return ( (*this - ovec).length_squared() < c_epsilon2 ? TRUE : FALSE );
87 }
88 
89 
90 void MVec::move_to_line( const MVec& from, const MVec& to ){
91 
92  MVec base = to - from;
93  MVec vec = *this - from;
94  double b2 = base.length_squared();
95  double dot = base%vec;
96  if (dot <= 0.0) {
97  *this = from;
98  return;
99  }
100  double percent2 = ((dot*dot)/b2)/b2;
101  if (percent2 >= 1.0){
102  *this = to;
103  return;
104  }
105  double delta = sqrt (percent2);
106  *this = from * ( 1.0 - delta ) + to * delta;
107 }
#define FALSE
Definition: vinci.h:133
void int int REAL REAL * y
Definition: read.cpp:74
Definition: MVec.hpp:8
double sqrt(double d)
Definition: double.h:73
*********************************************************************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
void int int int REAL REAL REAL * z
Definition: write.cpp:76
double length_squared() const
Definition: MVec.hpp:86
void int int REAL * x
Definition: read.cpp:74
#define TRUE
Definition: vinci.h:134
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
std::istream & operator>>(std::istream &is, CGAL::Aff_transformation_2< R > &t)
std::ostream & operator<<(std::ostream &os, const COM_exception &ex)
Print out a given exception.
MVec operator*(double val) const
Definition: MVec.cpp:57
MVec operator+(const MVec &ovec) const
Definition: MVec.cpp:39
const double c_epsilon2
Definition: MVec.hpp:64
double d_y
Definition: MVec.hpp:58