Vector3.cpp

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00024 #include <math.h>
00025 
00026 #include "Vector3.h"
00027 
00028 
00030 void Vector3::Set(double a, double b, double c) { x=a; y=b; z=c; }
00031 
00033 bool Vector3::IsZero() const
00034 {
00035     return ((x==0.f) && (y==0.f) && (z==0.f));
00036 }
00037 
00039 bool Vector3::IsNearlyZero() const
00040 {
00041     return ( (fabs(x)<EPSILON) && (fabs(y)<EPSILON) && (fabs(z)<EPSILON) );
00042 }
00043 
00045 bool Vector3::IsNearlyEqual(const Vector3& v) const
00046 {
00047     return ( (fabs(x-v.x)<EPSILON) && (fabs(y-v.y)<EPSILON) && (fabs(z-v.z)<EPSILON) );
00048 }
00049 
00051 Vector3 Vector3::operator/( double Scale ) const
00052 {
00053     double invScale = 1.f/Scale;
00054     return Vector3( x * invScale, y * invScale, z * invScale );
00055 }
00056 
00058 Vector3 Vector3::operator/=( double Scale )
00059 {
00060     double invScale = 1.f/Scale;
00061     x *= invScale;
00062     y *= invScale;
00063     z *= invScale;
00064     return *this;
00065 }
00066 
00068 double Vector3::Norm() const
00069 {
00070     return sqrt( x*x + y*y + z*z );
00071 }
00072 
00074 double Vector3::NormSquared() const
00075 {
00076     return x*x + y*y + z*z;
00077 }
00078 
00080 bool Vector3::Normalize()
00081 {
00082     double SquareSum = x*x + y*y + z*z;
00083     if( SquareSum >= EPSILON )
00084     {
00085         double invNorm = 1.f/sqrt(SquareSum);
00086         x *= invNorm;
00087         y *= invNorm;
00088         z *= invNorm;
00089         return true;
00090     }
00091     return false;
00092 }
00093 
00095 Vector3 Vector3::GetNormalized() const
00096 {
00097     Vector3 result(*this);
00098     double SquareSum = x*x + y*y + z*z;
00099     if( SquareSum >= EPSILON )
00100     {
00101         double invNorm = 1.f/sqrt(SquareSum);
00102         result.x *= invNorm;
00103         result.y *= invNorm;
00104         result.z *= invNorm;
00105     }
00106     return result;
00107 }
00108 

Generated on 20 Oct 2014 for Hugintrunk by  doxygen 1.4.7