Geom Software - C++ Programming and Geometry Libraries
Fade3D Documentation pages v0.99
/home/geom/repo/dev/geomDev/dt3/dt3Library/Vector3.h
1 // Copyright (C) Geom Software e.U, Bernhard Kornberger, Graz/Austria
2 //
3 // This file is part of the Fade3D library. The student license is free
4 // of charge and covers personal non-commercial research. Licensees
5 // holding a commercial license may use this file in accordance with
6 // the Commercial License Agreement.
7 //
8 // This software is provided AS IS with NO WARRANTY OF ANY KIND,
9 // INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS
10 // FOR A PARTICULAR PURPOSE.
11 //
12 // Please contact the author if any conditions of this licensing are
13 // not clear to you.
14 //
15 // Author: Bernhard Kornberger, bkorn (at) geom.at
16 // http://www.geom.at
17 
18 
19 #pragma once
20 #include "common.h"
21 
22 namespace FADE3D {
23 
26 class Vector3
27 {
28 public:
32  Vector3(const double x_,const double y_,const double z_);
33 
37  Vector3();
38 
39 
42  double x() const;
43 
46  double y() const;
47 
50  double z() const;
51 
54  void set(const double x_,const double y_,const double z_);
55 
58  double length() const;
59 
62  double operator*(const Vector3& other) const;
63 
64 
67  Vector3 operator*(double val) const;
68 
69 
72  Vector3 operator/(double val) const;
73 
74 protected:
75  double valX;
76  double valY;
77  double valZ;
78 };
79 
80 
81 
82 
83 // Free functions
84 
85 
86 inline std::ostream &operator<<(std::ostream &stream, const Vector3& vec)
87 {
88  stream << "Vector3: "<<vec.x()<<", "<<vec.y()<<", "<<vec.z();
89  return stream;
90 }
91 
95 inline Vector3 crossProduct(const Vector3& vec0,const Vector3& vec1)
96 {
97  double x=vec0.y() * vec1.z() - vec0.z() * vec1.y();
98  double y=vec0.z() * vec1.x() - vec0.x() * vec1.z();
99  double z=vec0.x() * vec1.y() - vec0.y() * vec1.x();
100  return Vector3(x,y,z);
101 }
102 
103 
107 inline Vector3 normalize(const Vector3& other)
108 {
109  double len(other.length());
110  if(len>0)
111  {
112  return Vector3(other.x()/len,other.y()/len,other.z()/len);
113  }
114  else
115  {
116  std::cout<<"warning: normalize(const Vector3& other), Null length vector!"<<std::endl;// COUTOK
117  return Vector3(0,0,0);
118  }
119 }
120 
121 
122 inline Vector3 operator-(const Vector3& in)
123 {
124  return Vector3(-in.x(),-in.y(),-in.z());
125 }
126 
127 
128 inline Vector3 operator*(double d,const Vector3& vec)
129 {
130  return Vector3(d*vec.x(),d*vec.y(),d*vec.z());
131 }
132 
133 
134 } // (namespace)
double y() const
Get the y-value.
double operator*(const Vector3 &other) const
Scalar product.
Definition: Ball3.h:16
double length() const
Get the length of the vector.
double x() const
Get the x-value.
Vector3 operator/(double val) const
Divide by a scalar value.
3D Vector
Definition: Vector3.h:26
Vector3()
Constructor The vector is initialized to (0,0,0)
double z() const
Get the z-value.