Cleaver Tetrahedral Meshing  2.2.1
Cleaving algorithm for high quality tetrahedral meshing
All Classes Pages
vec3.h
1 //-------------------------------------------------------------------
2 //-------------------------------------------------------------------
3 //
4 // Cleaver - A MultiMaterial Conforming Tetrahedral Meshing Library
5 //
6 // -- vector library
7 //
8 // Author: Jonathan Bronson (bronson@sci.utah.edu)
9 //
10 //-------------------------------------------------------------------
11 //-------------------------------------------------------------------
12 //
13 // Copyright (C) 2011, 2012, Jonathan Bronson
14 // Scientific Computing & Imaging Institute
15 // University of Utah
16 //
17 // Permission is hereby granted, free of charge, to any person
18 // obtaining a copy of this software and associated documentation
19 // files ( the "Software" ), to deal in the Software without
20 // restriction, including without limitation the rights to use,
21 // copy, modify, merge, publish, distribute, sublicense, and/or
22 // sell copies of the Software, and to permit persons to whom the
23 // Software is furnished to do so, subject to the following
24 // conditions:
25 //
26 // The above copyright notice and this permission notice shall
27 // be included in all copies or substantial portions of the
28 // Software.
29 //
30 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
31 // KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
32 // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
33 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
34 // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
35 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
36 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
37 // USE OR OTHER DEALINGS IN THE SOFTWARE.
38 //-------------------------------------------------------------------
39 //-------------------------------------------------------------------
40 
41 
42 #ifndef VEC3_H
43 #define VEC3_H
44 
45 #ifndef PI
46 #define PI 3.14159265
47 #endif
48 
49 #include <iostream>
50 #include <algorithm>
51 
52 #ifdef min
53 #undef min
54 #endif
55 
56 #ifdef max
57 #undef max
58 #endif
59 
60 namespace cleaver
61 {
62 
63 class vec3
64 {
65 public:
66  vec3();
67  vec3(double x, double y, double z);
68  vec3(const vec3 &x);
69 
70 public:
71  double x;
72  double y;
73  double z;
74 
75  bool operator!=(const vec3 &a) const;
76  bool operator==(const vec3 &a) const;
77  bool operator<=(const vec3 &a) const;
78  bool operator>=(const vec3 &a) const;
79  bool operator<(const vec3 &a) const;
80  bool operator>(const vec3 &a) const;
81  vec3& operator=(const vec3 &a);
82  vec3& operator+=(const vec3 &a);
83  vec3& operator*=(double c);
84  vec3& operator/=(double c);
85 
86  double& operator[](const size_t);
87  double operator[](const size_t) const;
88 
89  double dot(const vec3 &b) const;
90  vec3 cross(const vec3 &b);
91 
92  static vec3 zero;
93  static vec3 unitX;
94  static vec3 unitY;
95  static vec3 unitZ;
96  static vec3 min(const vec3 &a, const vec3 &b);
97  static vec3 max(const vec3 &a, const vec3 &b);
98 
99  std::string toString() const;
100  friend std::ostream& operator<<(std::ostream &stream, const vec3 &v);
101 };
102 
103 vec3 cross(const vec3 &a, const vec3 &b);
104 double dot(const vec3 &a, const vec3 &b);
105 double length(const vec3 &a);
106 double L1(const vec3 &a);
107 double L2(const vec3 &a);
108 double clamp(double value, double min, double max);
109 int clamp(int value, int min, int max);
110 vec3 normalize(const vec3 &v1);
111 
112 double vec2polar(const vec3 &a);
113 
114 double angleBetween(const vec3 &a, const vec3 &b);
115 
116 vec3 operator+(const vec3 &a, const vec3 &b);
117 vec3 operator-(const vec3 &a, const vec3 &b);
118 vec3 operator*(const vec3 &a, double b);
119 vec3 operator*(double a, const vec3 &b);
120 vec3 operator/(const vec3 &a, double b);
121 
122 }
123 
124 #endif // VEC3_H