NVector3.cpp
Go to the documentation of this file.
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.4.0.
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 "NVector3.h"
46 #include "Vector3.h"
47 
48 using namespace vrender;
49 
50 NVector3::NVector3(const Vector3 &u,bool normalization)
51 {
52  setXYZ(u[0],u[1],u[2],normalization);
53 }
54 /*
55 Vector3 operator+(const NVector3 &u,const Vector3 &v)
56 {
57  return Vector3(u[0]+v[0],u[1]+v[1],u[2]+v[2]);
58 }
59 
60 Vector3 operator+(const Vector3 &u,const NVector3 &v)
61 {
62  return Vector3(u[0]+v[0],u[1]+v[1],u[2]+v[2]);
63 }
64 
65 Vector3 operator+(const NVector3 &u,const NVector3 &v)
66 {
67  return Vector3(u[0]+v[0],u[1]+v[1],u[2]+v[2]);
68 }
69 
70 Vector3 operator-(const NVector3 &u,const Vector3 &v)
71 {
72  return Vector3(u[0]-v[0],u[1]-v[1],u[2]-v[2]);
73 }
74 
75 Vector3 operator-(const Vector3 &u,const NVector3 &v)
76 {
77  return Vector3(u[0]-v[0],u[1]-v[1],u[2]-v[2]);
78 }
79 
80 Vector3 operator-(const NVector3 &u,const NVector3 &v)
81 {
82  return Vector3(u[0]-v[0],u[1]-v[1],u[2]-v[2]);
83 }
84 */
85 double vrender::operator*(const NVector3 &u,const Vector3 &v)
86 {
87  return u[0]*v[0] + u[1]*v[1] + u[2]*v[2];
88 }
89 
90 double vrender::operator*(const Vector3 &u,const NVector3 &v)
91 {
92  return u[0]*v[0] + u[1]*v[1] + u[2]*v[2];
93 }
94 /*
95 double operator*(const NVector3 &u,const NVector3 &v)
96 {
97  return u[0]*v[0] + u[1]*v[1] + u[2]*v[2];
98 }
99 
100 Vector3 operator*(double r,const NVector3 &u)
101 {
102  return Vector3(r*u[0],r*u[1],r*u[2]);
103 }
104 
105 Vector3 operator/(const NVector3 &u,double r)
106 {
107  return Vector3(u[0]/r,u[1]/r,u[2]/r);
108 }
109 
110 
111 Vector3 operator^(const NVector3 &u,const Vector3 &v)
112 {
113  return Vector3( u[1]*v[2]-u[2]*v[1],
114  u[2]*v[0]-u[0]*v[2],
115  u[0]*v[1]-u[1]*v[0]);
116 }
117 
118 Vector3 operator^(const Vector3 &u,const NVector3 &v)
119 {
120  return Vector3( u[1]*v[2]-u[2]*v[1],
121  u[2]*v[0]-u[0]*v[2],
122  u[0]*v[1]-u[1]*v[0]);
123 }
124 
125 Vector3 operator^(const NVector3 &u,const NVector3 &v)
126 {
127  return Vector3( u[1]*v[2]-u[2]*v[1],
128  u[2]*v[0]-u[0]*v[2],
129  u[0]*v[1]-u[1]*v[0]);
130 }
131 */
132 // -----------------------------------------------------------------------------
135 {
136  _n[0] = 1.0;
137  _n[1] = 0.0;
138  _n[2] = 0.0;
139 }
140 
141 // -----------------------------------------------------------------------------
144 {
145  _n[0] = u._n[0] ;
146  _n[1] = u._n[1] ;
147  _n[2] = u._n[2] ;
148 }
149 // -----------------------------------------------------------------------------
151 void NVector3::setXYZ(double x,double y,double z,bool normalization)
152 {
153  _n[0] = x;
154  _n[1] = y;
155  _n[2] = z;
156  if ( normalization ) normalize();
157 }
158 
159 // -----------------------------------------------------------------------------
162 {
163  if ( &u != this )
164  {
165  _n[0] = u[0];
166  _n[1] = u[1];
167  _n[2] = u[2];
168  }
169  return *this;
170 }
171 // -----------------------------------------------------------------------------
173 std::ostream& operator<<(std::ostream& out,const NVector3& u)
174 {
175  out << u[0] << " " << u[1] << " " << u[2];
176  return out;
177 }
178 
179 // -----------------------------------------------------------------------------
184 {
185  double n = _n[0]*_n[0]+_n[1]*_n[1]+_n[2]*_n[2] ;
186 
187  if ( n > 0.0 )
188  {
189  _n[0] /= n;
190  _n[1] /= n;
191  _n[2] /= n;
192  }
193  else
194  throw std::runtime_error("Attempt to normalize a null 3D vector.") ;
195 }
196 
double y() const
Definition: NVector3.h:68
void setXYZ(double x, double y, double z, bool normalization=true)
Writing X,Y and Z coordinates.
Definition: NVector3.cpp:151
NVector3()
Default constructor (the default normalized vector is (1,0,0))
Definition: NVector3.cpp:134
NVector3 & operator=(const NVector3 &u)
Assignment.
Definition: NVector3.cpp:161
friend std::ostream & operator<<(std::ostream &out, const NVector3 &u)
Out stream override: prints the 3 normalized vector components.
Definition: NVector3.cpp:173
double z() const
Definition: NVector3.h:69
Vector2 operator*(double r, const Vector2 &u)
Left multiplication by a real value.
Definition: Vector2.cpp:101
double _n[3]
normalized vector
Definition: NVector3.h:114
double x() const
Definition: NVector3.h:67


octovis
Author(s): Kai M. Wurm , Armin Hornung
autogenerated on Mon Jun 10 2019 14:00:25