LoAdSG
math_lib.h
1/**********************************************************************************
2* Author: Christoph Pflaum, Riccarda Scherner-Griesshammer
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#include <fstream>
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(std::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 double& operator[](int i) {
38 if(i==0) return x;
39 if(i==1) return y;
40 return z;
41 }
42};
43
44inline double MIN(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
50inline double MAX(D3vector V) {
51 if(V.x>V.z && V.x>V.y) return V.x;
52 if(V.y>V.z && V.y>V.x) return V.y;
53 return V.z;
54}
55
56/*
57inline D3vector MAX(D3vector V1, D3vector V2) {
58 return D3vector(MAX(V1.x,V2.x),MAX(V1.y,V2.y),MAX(V1.z,V2.z));
59}
60
61inline D3vector MIN(D3vector V1, D3vector V2) {
62 return D3vector(MIN(V1.x,V2.x),MIN(V1.y,V2.y),MIN(V1.z,V2.z));
63}
64*/
65
66inline D3vector operator+(const D3vector& v,const D3vector& w) {
67 return D3vector(v.x+w.x,v.y+w.y,v.z+w.z);
68}
69
70inline D3vector operator*(const D3vector& v,const D3vector& w) {
71 return D3vector(v.x*w.x,v.y*w.y,v.z*w.z);
72}
73
74inline D3vector operator/(const D3vector& v,const D3vector& w) {
75 return D3vector(v.x/w.x,v.y/w.y,v.z/w.z);
76}
77
78inline D3vector operator-(const D3vector& v,const D3vector& w) {
79 return D3vector(v.x-w.x,v.y-w.y,v.z-w.z);
80}
81
82inline D3vector operator/(const D3vector& v,const double f) {
83 return D3vector(v.x/f,v.y/f,v.z/f);
84}
85
86inline D3vector operator*(const D3vector& v,const double f) {
87 return D3vector(v.x*f,v.y*f,v.z*f);
88}
89
90inline D3vector operator*(const double f, const D3vector& v) {
91 return D3vector(v.x*f,v.y*f,v.z*f);
92}
93
94inline bool operator<(const D3vector& v,const D3vector& w) {
95 return (v.x<w.x && v.y<w.y && v.z<w.z);
96}
97inline bool operator==(const D3vector& v,const D3vector& w) {
98 return (v.x==w.x && v.y==w.y && v.z==w.z);
99}
100
101
103// Implementierung einiger Memberfunktionen
105
106
107// D3vector
108// ----------
109
110inline void D3vector::Print() {
111 std::cout << "Coordinate: " << x << ", " << y << ", " << z << ";";
112}
113
114inline void D3vector::Print(std::ofstream *Datei) {
115 *Datei << x << " " << y << " " << z;
116}
117
118#endif // MATHLIB_H_
119
120