ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-2.0/src/math/Vector3.hpp
Revision: 1630
Committed: Thu Oct 21 21:31:39 2004 UTC (19 years, 8 months ago) by tim
File size: 3656 byte(s)
Log Message:
Snapshot and SnapshotManager in progress

File Contents

# Content
1 /*
2 * Copyright (C) 2000-2004 Object Oriented Parallel Simulation Engine (OOPSE) project
3 *
4 * Contact: oopse@oopse.org
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public License
8 * as published by the Free Software Foundation; either version 2.1
9 * of the License, or (at your option) any later version.
10 * All we ask is that proper credit is given for our work, which includes
11 * - but is not limited to - adding the above copyright notice to the beginning
12 * of your source code files, and to any copyright notice that you may distribute
13 * with programs based on this work.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 *
24 */
25
26 /**
27 * @file Vector3.hpp
28 * @author Teng Lin
29 * @date 09/14/2004
30 * @version 1.0
31 */
32
33 #ifndef MATH_VECTOR3_HPP
34 #define MATH_VECTOR3_HPP
35
36 #include <cassert>
37 #include <cmath>
38
39 #include "Vector.hpp"
40
41 namespace oopse {
42
43 /**
44 * @class Vector3 Vector3.hpp "math/Vector3.hpp"
45 * @brief
46 */
47
48 template<typename Real>
49 class Vector3 : public Vector<Real, 3>{
50 public:
51 typedef Real ElemType;
52 typedef Real* ElemPoinerType;
53
54 Vector3() : Vector<Real, 3>(){}
55
56 /** Constructs and initializes a Vector3 from x, y, z coordinates */
57 inline Vector3( double x, double y, double z) {
58 data_[0] = x;
59 data_[1] = y;
60 data_[2] = z;
61 }
62
63 inline Vector3(const Vector<Real, 3>& v) : Vector<Real, 3>(v) {}
64
65 inline Vector3<Real>& operator = (const Vector<Real, 3>& v) {
66 if (this == &v) { return *this; }
67 Vector<Real, 3>::operator=(v);
68 return *this;
69 }
70
71 /**
72 * Retunrs reference of the first element of Vector3.
73 * @return reference of the first element of Vector3
74 */
75 inline Real& x() { return data_[0];}
76
77 /**
78 * Retunrs the first element of Vector3.
79 * @return the first element of Vector3
80 */
81 inline Real x() const { return data_[0];}
82
83 /**
84 * Retunrs reference of the second element of Vector3.
85 * @return reference of the second element of Vector3
86 */
87 inline Real& y() { return data_[1];}
88
89 /**
90 * Retunrs the second element of Vector3.
91 * @return c the second element of Vector3
92 */
93 inline Real y() const { return data_[1];}
94
95 /**
96 * Retunrs reference of the third element of Vector3.
97 * @return reference of the third element of Vector3
98 */
99 inline Real& z() { return data_[2];}
100
101 /**
102 * Retunrs the third element of Vector3.
103 * @return f the third element of Vector3
104 */
105 inline Real z() const { return data_[2];}
106
107 };
108
109 /**
110 * Returns the cross product of two Vectors
111 * @param v1 first vector
112 * @param v2 second vector
113 * @return the cross product of v1 and v2
114 * @see #vector::dot
115 */
116 template<typename Real>
117 Vector3<Real> cross( const Vector3<Real>& v1, const Vector3<Real>& v2 ) {
118 Vector3<Real> result;
119
120 result.x() = v1.y() * v2.z() - v1.z() * v2.y();
121 result.y() = v1.z() * v2.x() - v1.x() * v2.z();
122 result.z() = v1.x() * v2.y() - v1.y() * v2.x();
123
124 return result;
125 }
126
127 typedef Vector3<double> Vector3d;
128
129 }
130
131 #endif