MercuryDPM  Alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Matrix.h
Go to the documentation of this file.
1 //Copyright (c) 2013-2014, The MercuryDPM Developers Team. All rights reserved.
2 //For the list of developers, see <http://www.MercuryDPM.org/Team>.
3 //
4 //Redistribution and use in source and binary forms, with or without
5 //modification, are permitted provided that the following conditions are met:
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above copyright
9 // notice, this list of conditions and the following disclaimer in the
10 // documentation and/or other materials provided with the distribution.
11 // * Neither the name MercuryDPM nor the
12 // names of its contributors may be used to endorse or promote products
13 // derived from this software without specific prior written permission.
14 //
15 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 //ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 //WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 //DISCLAIMED. IN NO EVENT SHALL THE MERCURYDPM DEVELOPERS TEAM BE LIABLE FOR ANY
19 //DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 //(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 //LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 //ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 //(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 //SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 
26 #ifndef MATRIX_H
27 #define MATRIX_H
28 
29 #include <cmath>
30 #include <sstream>
31 #include "Vector.h"
32 
36 class Matrix3D
37 {
38 public:
42  Mdouble XX, XY, XZ, YX, YY, YZ, ZX, ZY, ZZ;
43 
47  Matrix3D();
48 
52  Matrix3D(const Mdouble xx, const Mdouble xy, const Mdouble xz, const Mdouble yx, const Mdouble yy, const Mdouble yz, const Mdouble zx, const Mdouble zy, const Mdouble zz);
53 
57  void setZero();
58 
62  double trace() const;
63 
67  Matrix3D operator +(const Matrix3D& A) const;
68 
72  Matrix3D operator -(const Matrix3D& A) const;
73 
77  Matrix3D operator +(const Mdouble a) const;
78 
82  Matrix3D operator -(const Mdouble a) const;
83 
87  Matrix3D operator *(const Mdouble a) const;
88 
92  Vec3D operator *(const Vec3D& a) const;
93 
97  Matrix3D operator *(const Matrix3D& a) const;
98 
102  Matrix3D operator /(const Mdouble a) const;
103 
107  friend std::ostream& operator<<(std::ostream& os, const Matrix3D &A);
108 
112  friend std::istream& operator>>(std::istream& is, Matrix3D &A);
113 
117  Matrix3D& operator+=(const Matrix3D &A);
118 
122  Matrix3D& operator-=(const Matrix3D &A);
123 
127  Matrix3D& operator/=(const Mdouble a);
128 
132  static Matrix3D square(const Matrix3D &A);
133 
137  static Matrix3D sqrt(const Matrix3D &A);
138 
142  static Matrix3D dyadic(const Vec3D& a, const Vec3D& b);
143 
147  static Matrix3D cross(const Vec3D& a, const Matrix3D& b);
148 
149 };
150 
151 
152 
153 #endif
Mdouble XY
Definition: Matrix.h:42
Matrix3D operator-(const Matrix3D &A) const
Matrix subtraction.
Definition: Matrix.cc:91
double trace() const
Mean of the diagonal elements.
Definition: Matrix.cc:68
Matrix3D & operator+=(const Matrix3D &A)
Matrix addition.
Definition: Matrix.cc:203
Matrix3D & operator/=(const Mdouble a)
Scalar division.
Definition: Matrix.cc:241
Mdouble ZY
Definition: Matrix.h:42
Mdouble XZ
Definition: Matrix.h:42
Mdouble ZX
Definition: Matrix.h:42
double Mdouble
Matrix3D operator/(const Mdouble a) const
Scalar division.
Definition: Matrix.cc:165
Mdouble ZZ
Definition: Matrix.h:42
Mdouble YZ
Definition: Matrix.h:42
static Matrix3D dyadic(const Vec3D &a, const Vec3D &b)
Calculates the dyadic product of a two Vec3D: .
Definition: Matrix.cc:285
Matrix3D operator*(const Mdouble a) const
Scalar multiplication.
Definition: Matrix.cc:127
static Matrix3D cross(const Vec3D &a, const Matrix3D &b)
'Special' cross product; CP of vector with each column of a matrix
Definition: Matrix.cc:299
Mdouble YX
Definition: Matrix.h:42
Matrix3D operator+(const Matrix3D &A) const
Matrix addition.
Definition: Matrix.cc:78
friend std::ostream & operator<<(std::ostream &os, const Matrix3D &A)
Add elements to ostream.
Definition: Matrix.cc:178
Matrix3D & operator-=(const Matrix3D &A)
Matrix substraction.
Definition: Matrix.cc:222
static Matrix3D sqrt(const Matrix3D &A)
Calculates the pointwise square root.
Definition: Matrix.cc:272
Mdouble XX
all nine matrix elements
Definition: Matrix.h:42
void setZero()
Sets all elements to zero.
Definition: Matrix.cc:58
Mdouble YY
Definition: Matrix.h:42
Implementation of a 3D matrix.
Definition: Matrix.h:36
Implementation of a 3D vector (by Vitaliy).
Definition: Vector.h:45
Matrix3D()
default constructor
Definition: Matrix.cc:32
static Matrix3D square(const Matrix3D &A)
Calculates the pointwise square.
Definition: Matrix.cc:260
friend std::istream & operator>>(std::istream &is, Matrix3D &A)
Add elements to istream.
Definition: Matrix.cc:192