~reducedmodelling/fluidity/ROM_Non-intrusive-ann

« back to all changes in this revision

Viewing changes to include/Wm4Vector2.h

  • Committer: fangf at ac
  • Date: 2012-11-06 12:21:31 UTC
  • mto: This revision was merged to the branch mainline in revision 3989.
  • Revision ID: fangf@imperial.ac.uk-20121106122131-u2zvt7fxc1r3zeou
updated

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Wild Magic Source Code
 
2
// David Eberly
 
3
// http://www.geometrictools.com
 
4
// Copyright (c) 1998-2008
 
5
//
 
6
// This library is free software; you can redistribute it and/or modify it
 
7
// under the terms of the GNU Lesser General Public License as published by
 
8
// the Free Software Foundation; either version 2.1 of the License, or (at
 
9
// your option) any later version.  The license is available for reading at
 
10
// either of the locations:
 
11
//     http://www.gnu.org/copyleft/lgpl.html
 
12
//     http://www.geometrictools.com/License/WildMagicLicense.pdf
 
13
//
 
14
// Version: 4.0.3 (2007/03/07)
 
15
 
 
16
#ifndef WM4VECTOR2_H
 
17
#define WM4VECTOR2_H
 
18
 
 
19
#include "Wm4FoundationLIB.h"
 
20
#include "Wm4Math.h"
 
21
 
 
22
namespace Wm4
 
23
{
 
24
 
 
25
template <class Real>
 
26
class Vector2
 
27
{
 
28
public:
 
29
    // construction
 
30
    Vector2 ();  // uninitialized
 
31
    Vector2 (Real fX, Real fY);
 
32
    Vector2 (const Real* afTuple);
 
33
    Vector2 (const Vector2& rkV);
 
34
 
 
35
    // coordinate access
 
36
    inline operator const Real* () const;
 
37
    inline operator Real* ();
 
38
    inline Real operator[] (int i) const;
 
39
    inline Real& operator[] (int i);
 
40
    inline Real X () const;
 
41
    inline Real& X ();
 
42
    inline Real Y () const;
 
43
    inline Real& Y ();
 
44
 
 
45
    // assignment
 
46
    inline Vector2& operator= (const Vector2& rkV);
 
47
 
 
48
    // comparison
 
49
    bool operator== (const Vector2& rkV) const;
 
50
    bool operator!= (const Vector2& rkV) const;
 
51
    bool operator<  (const Vector2& rkV) const;
 
52
    bool operator<= (const Vector2& rkV) const;
 
53
    bool operator>  (const Vector2& rkV) const;
 
54
    bool operator>= (const Vector2& rkV) const;
 
55
 
 
56
    // arithmetic operations
 
57
    inline Vector2 operator+ (const Vector2& rkV) const;
 
58
    inline Vector2 operator- (const Vector2& rkV) const;
 
59
    inline Vector2 operator* (Real fScalar) const;
 
60
    inline Vector2 operator/ (Real fScalar) const;
 
61
    inline Vector2 operator- () const;
 
62
 
 
63
    // arithmetic updates
 
64
    inline Vector2& operator+= (const Vector2& rkV);
 
65
    inline Vector2& operator-= (const Vector2& rkV);
 
66
    inline Vector2& operator*= (Real fScalar);
 
67
    inline Vector2& operator/= (Real fScalar);
 
68
 
 
69
    // vector operations
 
70
    inline Real Length () const;
 
71
    inline Real SquaredLength () const;
 
72
    inline Real Dot (const Vector2& rkV) const;
 
73
    inline Real Normalize ();
 
74
 
 
75
    // returns (y,-x)
 
76
    inline Vector2 Perp () const;
 
77
 
 
78
    // returns (y,-x)/sqrt(x*x+y*y)
 
79
    inline Vector2 UnitPerp () const;
 
80
 
 
81
    // returns DotPerp((x,y),(V.x,V.y)) = x*V.y - y*V.x
 
82
    inline Real DotPerp (const Vector2& rkV) const;
 
83
 
 
84
    // Compute the barycentric coordinates of the point with respect to the
 
85
    // triangle <V0,V1,V2>, P = b0*V0 + b1*V1 + b2*V2, where b0 + b1 + b2 = 1.
 
86
    void GetBarycentrics (const Vector2& rkV0, const Vector2& rkV1,
 
87
        const Vector2& rkV2, Real afBary[3]) const;
 
88
 
 
89
    // Gram-Schmidt orthonormalization.  Take linearly independent vectors U
 
90
    // and V and compute an orthonormal set (unit length, mutually
 
91
    // perpendicular).
 
92
    static void Orthonormalize (Vector2& rkU, Vector2& rkV);
 
93
 
 
94
    // Input V must be a nonzero vector.  The output is an orthonormal basis
 
95
    // {U,V}.  The input V is normalized by this function.  If you know V is
 
96
    // already unit length, use U = V.Perp().
 
97
    static void GenerateOrthonormalBasis (Vector2& rkU, Vector2& rkV);
 
98
 
 
99
    // Compute the extreme values.
 
100
    static void ComputeExtremes (int iVQuantity, const Vector2* akPoint,
 
101
        Vector2& rkMin, Vector2& rkMax);
 
102
 
 
103
    // special vectors
 
104
    WM4_FOUNDATION_ITEM static const Vector2 ZERO;    // (0,0)
 
105
    WM4_FOUNDATION_ITEM static const Vector2 UNIT_X;  // (1,0)
 
106
    WM4_FOUNDATION_ITEM static const Vector2 UNIT_Y;  // (0,1)
 
107
    WM4_FOUNDATION_ITEM static const Vector2 ONE;     // (1,1)
 
108
 
 
109
private:
 
110
    // support for comparisons
 
111
    int CompareArrays (const Vector2& rkV) const;
 
112
 
 
113
    Real m_afTuple[2];
 
114
};
 
115
 
 
116
// arithmetic operations
 
117
template <class Real>
 
118
Vector2<Real> operator* (Real fScalar, const Vector2<Real>& rkV);
 
119
 
 
120
// debugging output
 
121
template <class Real>
 
122
std::ostream& operator<< (std::ostream& rkOStr, const Vector2<Real>& rkV);
 
123
 
 
124
#include "Wm4Vector2.inl"
 
125
 
 
126
typedef Vector2<float> Vector2f;
 
127
typedef Vector2<double> Vector2d;
 
128
typedef Vector2<long double> Vector2ld;
 
129
 
 
130
}
 
131
 
 
132
#endif