LoAdSG
math_lib.h
1/**********************************************************************************
2* Author: Christoph Pflaum, Riccarda Scherner-Griesshammer, Rainer Hartmann
3 * Department Informatik Lehrstuhl 10 - Systemsimulation
4 * Friedrich-Alexander Universität Erlangen-Nürnberg
5 *
6*********************************************/
7
8// ------------------------------------------------------------
9// math_lib.h
10//
11// ------------------------------------------------------------
12
13#ifndef MATHLIB_H_
14#define MATHLIB_H_
15
16
18// a simple 3D vector class
20
21class D3vector {
22 public:
23 double x,y,z;
24 D3vector(double cx, double cy, double cz) : x(cx), y(cy), z(cz) {};
25 explicit D3vector(double c) : x(c), y(c), z(c) {};
26 D3vector() : x(0), y(0), z(0) {};
27 ~D3vector(){};
28 void Print();
29 void Print(ofstream *Datei);
30 void operator=(const D3vector& v) { x=v.x; y=v.y; z=v.z; }
31 double operator[](int i) {
32 if(i==0) return x;
33 if(i==1) return y;
34 return z;
35 }
36};
37
38inline double MIN(D3vector V) {
39 if(V.x<V.z && V.x<V.y) return V.x;
40 if(V.y<V.z && V.y<V.x) return V.y;
41 return V.z;
42}
43
44inline double MAX(D3vector V) {
45 if(V.x>V.z && V.x>V.y) return V.x;
46 if(V.y>V.z && V.y>V.x) return V.y;
47 return V.z;
48}
49
50/*
51inline D3vector MAX(D3vector V1, D3vector V2) {
52 return D3vector(MAX(V1.x,V2.x),MAX(V1.y,V2.y),MAX(V1.z,V2.z));
53}
54
55inline D3vector MIN(D3vector V1, D3vector V2) {
56 return D3vector(MIN(V1.x,V2.x),MIN(V1.y,V2.y),MIN(V1.z,V2.z));
57}
58*/
59
60inline D3vector operator+(const D3vector& v,const D3vector& w) {
61 return D3vector(v.x+w.x,v.y+w.y,v.z+w.z);
62}
63
64inline D3vector operator*(const D3vector& v,const D3vector& w) {
65 return D3vector(v.x*w.x,v.y*w.y,v.z*w.z);
66}
67
68inline D3vector operator/(const D3vector& v,const D3vector& w) {
69 return D3vector(v.x/w.x,v.y/w.y,v.z/w.z);
70}
71
72inline D3vector operator-(const D3vector& v,const D3vector& w) {
73 return D3vector(v.x-w.x,v.y-w.y,v.z-w.z);
74}
75
76inline D3vector operator/(const D3vector& v,const double f) {
77 return D3vector(v.x/f,v.y/f,v.z/f);
78}
79
80inline D3vector operator*(const D3vector& v,const double f) {
81 return D3vector(v.x*f,v.y*f,v.z*f);
82}
83
84inline D3vector operator*(const double f, const D3vector& v) {
85 return D3vector(v.x*f,v.y*f,v.z*f);
86}
87
88inline bool operator<(const D3vector& v,const D3vector& w) {
89 return (v.x<w.x && v.y<w.y && v.z<w.z);
90}
91inline bool operator==(const D3vector& v,const D3vector& w) {
92 return (v.x==w.x && v.y==w.y && v.z==w.z);
93}
94
95
97// Implementierung einiger Memberfunktionen
99
100
101// D3vector
102// ----------
103
104inline void D3vector::Print() {
105 cout << "Coordinate: " << x << ", " << y << ", " << z << ";";
106}
107
108inline void D3vector::Print(ofstream *Datei) {
109 *Datei << x << " " << y << " " << z;
110}
111
112
113#endif // MATHLIB_H_
114
115