Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Vector3.cpp
Go to the documentation of this file.
1 // -*- c-basic-offset: 4 -*-
24 #include <math.h>
25 
26 #include "Vector3.h"
27 
28 
30 void Vector3::Set(double a, double b, double c) { x=a; y=b; z=c; }
31 
33 bool Vector3::IsZero() const
34 {
35  return ((x==0.f) && (y==0.f) && (z==0.f));
36 }
37 
40 {
41  return ( (fabs(x)<EPSILON) && (fabs(y)<EPSILON) && (fabs(z)<EPSILON) );
42 }
43 
45 bool Vector3::IsNearlyEqual(const Vector3& v) const
46 {
47  return ( (fabs(x-v.x)<EPSILON) && (fabs(y-v.y)<EPSILON) && (fabs(z-v.z)<EPSILON) );
48 }
49 
51 Vector3 Vector3::operator/( double Scale ) const
52 {
53  double invScale = 1.f/Scale;
54  return Vector3( x * invScale, y * invScale, z * invScale );
55 }
56 
59 {
60  double invScale = 1.f/Scale;
61  x *= invScale;
62  y *= invScale;
63  z *= invScale;
64  return *this;
65 }
66 
68 double Vector3::Norm() const
69 {
70  return sqrt( x*x + y*y + z*z );
71 }
72 
74 double Vector3::NormSquared() const
75 {
76  return x*x + y*y + z*z;
77 }
78 
81 {
82  double SquareSum = x*x + y*y + z*z;
83  if( SquareSum >= EPSILON )
84  {
85  double invNorm = 1.f/sqrt(SquareSum);
86  x *= invNorm;
87  y *= invNorm;
88  z *= invNorm;
89  return true;
90  }
91  return false;
92 }
93 
96 {
97  Vector3 result(*this);
98  double SquareSum = x*x + y*y + z*z;
99  if( SquareSum >= EPSILON )
100  {
101  double invNorm = 1.f/sqrt(SquareSum);
102  result.x *= invNorm;
103  result.y *= invNorm;
104  result.z *= invNorm;
105  }
106  return result;
107 }
108 
double y
Definition: Vector3.h:47
Vector3()
default constructor
Definition: Vector3.h:52
Vector3 GetNormalized() const
return a normalized vector
Definition: Vector3.cpp:95
bool IsNearlyEqual(const Vector3 &v) const
comparison : nearly equal
Definition: Vector3.cpp:45
#define EPSILON
Definition: Vector3.h:32
Vector3 operator/(double Scale) const
operator /(double)
Definition: Vector3.cpp:51
bool Normalize()
Normalize.
Definition: Vector3.cpp:80
void Set(double a, double b, double c)
set
Definition: Vector3.cpp:30
double NormSquared() const
squared norm
Definition: Vector3.cpp:74
Vector3 operator/=(double Scale)
double divide
Definition: Vector3.cpp:58
double Norm() const
euclidien norm
Definition: Vector3.cpp:68
bool IsZero() const
comparison : zero
Definition: Vector3.cpp:33
double z
Definition: Vector3.h:47
general : Vector3 is a class for handling 3D Vectors manipulation.
Definition: Vector3.h:43
double x
x,y,z coordinates, 0 at the initialisation
Definition: Vector3.h:47
bool IsNearlyZero() const
comparison : nearly zero
Definition: Vector3.cpp:39