Vector3.cpp
1 /*
2  This file is part of the VRender library.
3  Copyright (C) 2005 Cyril Soler (Cyril.Soler@imag.fr)
4  Version 1.0.0, released on June 27, 2005.
5 
6  http://artis.imag.fr/Members/Cyril.Soler/VRender
7 
8  VRender is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12 
13  VRender is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with VRender; if not, write to the Free Software Foundation, Inc.,
20  51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
21 */
22 
23 /****************************************************************************
24 
25  Copyright (C) 2002-2013 Gilles Debunne. All rights reserved.
26 
27  This file is part of the QGLViewer library version 2.5.2.
28 
29  http://www.libqglviewer.com - contact@libqglviewer.com
30 
31  This file may be used under the terms of the GNU General Public License
32  versions 2.0 or 3.0 as published by the Free Software Foundation and
33  appearing in the LICENSE file included in the packaging of this file.
34  In addition, as a special exception, Gilles Debunne gives you certain
35  additional rights, described in the file GPL_EXCEPTION in this package.
36 
37  libQGLViewer uses dual licensing. Commercial/proprietary software must
38  purchase a libQGLViewer Commercial License.
39 
40  This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
41  WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
42 
43 *****************************************************************************/
44 
45 #include <iostream>
46 #include "Vector3.h"
47 #include "NVector3.h"
48 #include <math.h>
49 
50 #ifdef WIN32
51 # include <windows.h>
52 #endif
53 
54 using namespace vrender;
55 using namespace std;
56 
57 const Vector3 Vector3::inf(FLT_MAX, FLT_MAX, FLT_MAX);
58 
59 Vector3::Vector3 ()
60 {
61  _xyz[0] = 0.0;
62  _xyz[1] = 0.0;
63  _xyz[2] = 0.0;
64 }
65 
66 // -----------------------------------------------------------------------------
69 {
70 }
71 
72 // -----------------------------------------------------------------------------
74 Vector3::Vector3 (const Vector3& u)
75 {
76  setXYZ(u[0],u[1],u[2]);
77 }
78 
79 // -----------------------------------------------------------------------------
81 Vector3::Vector3 (const NVector3& u)
82 {
83  setXYZ(u[0],u[1],u[2]);
84 }
85 
86 // -----------------------------------------------------------------------------
88 Vector3::Vector3 (double x,double y,double z)
89 {
90  setXYZ(x,y,z);
91 }
92 // -----------------------------------------------------------------------------
94 Vector3& Vector3::operator= (const NVector3& u)
95 {
96  _xyz[0] = u[0];
97  _xyz[1] = u[1];
98  _xyz[2] = u[2];
99  return ( *this );
100 }
101 
102 // -----------------------------------------------------------------------------
104 Vector3& Vector3::operator+= (const NVector3& u)
105 {
106  _xyz[0] += u[0];
107  _xyz[1] += u[1];
108  _xyz[2] += u[2];
109  return ( *this );
110 }
111 
112 // -----------------------------------------------------------------------------
114 Vector3& Vector3::operator-= (const NVector3& u)
115 {
116  _xyz[0] -= u[0];
117  _xyz[1] -= u[1];
118  _xyz[2] -= u[2];
119  return ( *this );
120 }
121 
122 // -----------------------------------------------------------------------------
124 Vector3 vrender::operator* (double r,const Vector3& u)
125 {
126  return ( Vector3(r*u[0], r*u[1], r*u[2]) );
127 }
128 
129 
130 // -----------------------------------------------------------------------------
132 double Vector3::norm () const
133 {
134  return sqrt( _xyz[0]*_xyz[0] + _xyz[1]*_xyz[1] + _xyz[2]*_xyz[2] );
135 }
136 
137 // -----------------------------------------------------------------------------
139 double Vector3::squareNorm () const
140 {
141  return _xyz[0]*_xyz[0] + _xyz[1]*_xyz[1] + _xyz[2]*_xyz[2];
142 }
143 
144 // -----------------------------------------------------------------------------
146 double Vector3::infNorm() const
147 {
148  return max(max(fabs(_xyz[0]),fabs(_xyz[1])),fabs(_xyz[2])) ;
149 }
150 
151 
152 // -----------------------------------------------------------------------------
154 std::ostream& vrender::operator<< (std::ostream& out,const Vector3& u)
155 {
156  out << u[0] << " " << u[1] << " " << u[2];
157  return ( out );
158 }
159 
160 Vector3 Vector3::mini(const Vector3& v1,const Vector3& v2)
161 {
162  return Vector3(min(v1[0],v2[0]),min(v1[1],v2[1]),min(v1[2],v2[2])) ;
163 }
164 
165 Vector3 Vector3::maxi(const Vector3& v1,const Vector3& v2)
166 {
167  return Vector3(max(v1[0],v2[0]),max(v1[1],v2[1]),max(v1[2],v2[2])) ;
168 }
169 
double norm() const
Norm.
Definition: Vector3.cpp:132
double infNorm() const
Infinite norm.
Definition: Vector3.cpp:146
~Vector3()
Default destructor.
Definition: Vector3.cpp:68
FARSA_UTIL_TEMPLATE const T max(const T &t1, const U &t2)
double squareNorm() const
Square norm (self dot product)
Definition: Vector3.cpp:139
FARSA_UTIL_TEMPLATE const T min(const T &t1, const U &t2)