ESyS-Particle
2.2
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
vec3.h
Go to the documentation of this file.
1
2
// //
3
// Copyright (c) 2003-2013 by The University of Queensland //
4
// Earth Systems Science Computational Centre (ESSCC) //
5
// http://www.uq.edu.au/esscc //
6
// //
7
// Primary Business: Brisbane, Queensland, Australia //
8
// Licensed under the Open Software License version 3.0 //
9
// http://www.opensource.org/licenses/osl-3.0.php //
10
// //
12
13
#ifndef __VEC3_H
14
#define __VEC3_H
15
16
#include <iostream>
17
#include <math.h>
18
#include <string>
19
20
#include "
Error.h
"
21
22
using
std::ostream;
23
using
std::istream;
24
using
std::string;
25
26
class
Mat3;
27
28
class
VecErr
:
public
MError
29
{
30
public
:
31
VecErr
(
const
string
&);
32
virtual
~VecErr
(){};
33
};
34
35
struct
VDMulVadd
;
36
struct
VDMul
;
37
38
class
Vec3
39
{
40
protected
:
41
double
data
[3];
42
43
public
:
44
// constructors
45
Vec3
();
46
Vec3
(
double
,
double
,
double
);
47
Vec3
(
const
Vec3
&);
48
49
// vec-vec operators
50
Vec3
&
operator=
(
const
Vec3
&);
51
Vec3
&
operator-=
(
const
Vec3
&);
52
Vec3
&
operator+=
(
const
Vec3
&);
53
Vec3
operator+
(
const
Vec3
&)
const
;
54
Vec3
operator-
(
const
Vec3
&)
const
;
55
double
operator*
(
const
Vec3
&)
const
;
56
inline
Vec3
operator-
() {
return
Vec3
(-
data
[0],-
data
[1],-
data
[2]); } ;
57
58
// vec-dbl ops
59
Vec3
operator*
(
double
)
const
;
60
Vec3
operator/
(
double
)
const
;
61
62
double
norm
()
const
;
63
double
norm2
()
const
;
64
Vec3
unit
()
const
;
65
Vec3
unit_s
()
const
;
//safe version (throw exceptions)
66
double
max
()
const
;
67
double
min
()
const
;
68
69
bool
operator==
(
const
Vec3
&);
70
bool
operator!=
(
const
Vec3
&);
71
72
friend
Vec3
cmax
(
const
Vec3
&,
const
Vec3
&);
73
friend
Vec3
cmin
(
const
Vec3
&,
const
Vec3
&);
74
75
friend
Vec3
cross
(
const
Vec3
&,
const
Vec3
&);
76
77
friend
Vec3
operator*
(
double
,
const
Vec3
&);
78
79
//n+1-ary operators
80
void
mul_add_and_assign
(
const
Vec3
*,
const
Vec3
*,
const
double
&);
81
void
mul_and_assign
(
const
Vec3
*,
const
double
&);
82
83
Vec3
(
const
VDMulVadd
&);
84
Vec3
&
operator=
(
const
VDMulVadd
&);
85
86
Vec3
(
const
VDMul
&);
87
Vec3
&
operator=
(
const
VDMul
&);
88
89
//access stuff
90
inline
double
X
()
const
{
return
data
[0];};
91
inline
double
Y
()
const
{
return
data
[1];};
92
inline
double
Z
()
const
{
return
data
[2];};
93
inline
double
operator[]
(
int
i)
const
{
return
data
[i];};
94
inline
double
&
operator[]
(
int
i) {
return
data
[i];};
95
96
// in/output
97
friend
ostream&
operator <<
(ostream&,
const
Vec3
&);
98
friend
istream&
operator >>
(istream&,
Vec3
&);
99
100
friend
class
Mat3
;
101
};
102
103
//------------------------------
104
// stuff for 'n+1-ary' ops
105
// see Stroustrup, p.675 f.
106
//------------------------------
107
108
struct
VDMul
109
{
110
const
Vec3
&
v
;
111
const
double
d
;
112
113
VDMul
(
const
Vec3
& vv,
const
double
& dd):
v
(vv),
d
(dd){}
114
115
// operator Vec3(){return Vec3(v.x*d,v.y*d,v.z*d);};
116
};
117
118
inline
VDMul
operator*
(
const
Vec3
& vv,
const
double
& dd)
119
{
120
return
VDMul
(vv,dd);
121
}
122
123
struct
VDMulVadd
124
{
125
const
Vec3
&
v1
;
126
const
Vec3
&
v2
;
127
const
double
&
d
;
128
129
VDMulVadd
(
const
VDMul
vd,
const
Vec3
& vv):
v1
(vd.v),
v2
(vv),
d
(vd.
d
){}
130
131
//operator Vec3();
132
};
133
134
inline
VDMulVadd
operator+
(
const
VDMul
vd,
const
Vec3
& vv)
135
{
136
return
VDMulVadd
(vd,vv);
137
}
138
139
#endif
ntable
util
vec3.h
Generated on Mon May 6 2013 23:26:29 for ESyS-Particle by
1.8.3.1