Matrix3.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #ifndef GAZEBO_MATH_MATRIX3_HH_
18 #define GAZEBO_MATH_MATRIX3_HH_
19 
20 #include <assert.h>
21 #include <ignition/math/Matrix3.hh>
22 
23 #include "gazebo/math/Vector3.hh"
24 #include "gazebo/util/system.hh"
25 
26 #ifndef _WIN32
27  #pragma GCC diagnostic push
28  #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
29 #endif
30 
31 namespace gazebo
32 {
33  namespace math
34  {
37 
40  class GZ_MATH_VISIBLE Matrix3
41  {
43  public: Matrix3() GAZEBO_DEPRECATED(8.0);
44 
47  public: Matrix3(const Matrix3 &_m) GAZEBO_DEPRECATED(8.0);
48 
59  public: Matrix3(double _v00, double _v01, double _v02,
60  double _v10, double _v11, double _v12,
61  double _v20, double _v21, double _v22)
62  GAZEBO_DEPRECATED(8.0);
63 
66  public: Matrix3(const ignition::math::Matrix3d &_m)
67  GAZEBO_DEPRECATED(8.0);
68 
70  public: virtual ~Matrix3();
71 
74  public: ignition::math::Matrix3d Ign() const;
75 
80  public: void SetFromAxes(const Vector3 &_xAxis,
81  const Vector3 &_yAxis,
82  const Vector3 &_zAxis);
83 
84 
88  public: void SetFromAxis(const Vector3 &_axis, double _angle);
89 
93  public: void SetCol(unsigned int _c, const Vector3 &_v);
94 
97  public: Matrix3 Inverse() const;
98 
100  public: Matrix3 operator-(const Matrix3 &_m) const
101  {
102  return Matrix3(
103  // first row
104  this->m[0][0]-_m[0][0], this->m[0][1]-_m[0][1], this->m[0][2]-_m[0][2],
105  this->m[1][0]-_m[1][0], this->m[1][1]-_m[1][1], this->m[1][2]-_m[1][2],
106  this->m[2][0]-_m[2][0], this->m[2][1]-_m[2][1], this->m[2][2]-_m[2][2]);
107  }
108 
110  public: Matrix3 operator+(const Matrix3 &_m) const
111  {
112  return Matrix3(
113  // first row
114  this->m[0][0]+_m[0][0], this->m[0][1]+_m[0][1], this->m[0][2]+_m[0][2],
115  this->m[1][0]+_m[1][0], this->m[1][1]+_m[1][1], this->m[1][2]+_m[1][2],
116  this->m[2][0]+_m[2][0], this->m[2][1]+_m[2][1], this->m[2][2]+_m[2][2]);
117  }
118 
120  public: Matrix3 operator*(const double &_s) const
121  {
122  return Matrix3(
123  // first row
124  _s * this->m[0][0], _s * this->m[0][1], _s * this->m[0][2],
125  _s * this->m[1][0], _s * this->m[1][1], _s * this->m[1][2],
126  _s * this->m[2][0], _s * this->m[2][1], _s * this->m[2][2]);
127  }
128 
133  public: friend inline Matrix3 operator*(double _s,
134  const Matrix3 &_m)
135  { return _m * _s; }
136 
140  public: Matrix3 operator*(const Matrix3 &_m) const
141  {
142  return Matrix3(
143  // first row
144  this->m[0][0]*_m[0][0]+this->m[0][1]*_m[1][0]+this->m[0][2]*_m[2][0],
145  this->m[0][0]*_m[0][1]+this->m[0][1]*_m[1][1]+this->m[0][2]*_m[2][1],
146  this->m[0][0]*_m[0][2]+this->m[0][1]*_m[1][2]+this->m[0][2]*_m[2][2],
147  // second row
148  this->m[1][0]*_m[0][0]+this->m[1][1]*_m[1][0]+this->m[1][2]*_m[2][0],
149  this->m[1][0]*_m[0][1]+this->m[1][1]*_m[1][1]+this->m[1][2]*_m[2][1],
150  this->m[1][0]*_m[0][2]+this->m[1][1]*_m[1][2]+this->m[1][2]*_m[2][2],
151  // third row
152  this->m[2][0]*_m[0][0]+this->m[2][1]*_m[1][0]+this->m[2][2]*_m[2][0],
153  this->m[2][0]*_m[0][1]+this->m[2][1]*_m[1][1]+this->m[2][2]*_m[2][1],
154  this->m[2][0]*_m[0][2]+this->m[2][1]*_m[1][2]+this->m[2][2]*_m[2][2]);
155  }
156 
160  public: bool operator==(const Matrix3 &_m) const;
161 
165  public: inline math::Vector3 operator*(const math::Vector3 &_v) const
166  {
167  return math::Vector3(
168  this->m[0][0]*_v.x + this->m[0][1]*_v.y + this->m[0][2]*_v.z,
169  this->m[1][0]*_v.x + this->m[1][1]*_v.y + this->m[1][2]*_v.z,
170  this->m[2][0]*_v.x + this->m[2][1]*_v.y + this->m[2][2]*_v.z);
171  }
172 
176  public: inline const double *operator[](size_t _row) const
177  {
178  assert(_row < 3);
179  return this->m[_row];
180  }
181 
185  public: inline double *operator[](size_t _row)
186  {
187  assert(_row < 3);
188  return this->m[_row];
189  }
190 
191 
196  public: friend std::ostream &operator<<(std::ostream &_out,
197  const gazebo::math::Matrix3 &_m)
198  {
199  for (int i = 0; i < 3; i++)
200  {
201  for (int j = 0; j < 3; j++)
202  {
203  _out << _m.m[i][j] << " ";
204  }
205  _out << "\n";
206  }
207 
208  return _out;
209  }
210 
212  public: static const Matrix3 IDENTITY;
213 
215  public: static const Matrix3 ZERO;
216 
218  protected: double m[3][3];
219 
220  friend class Matrix4;
221  };
223  }
224 }
225 #ifndef _WIN32
226  #pragma GCC diagnostic pop
227 #endif
228 #endif
229 
230 
231 
double x
X location.
Definition: Vector3.hh:333
const double * operator[](size_t _row) const
Array subscript operator.
Definition: Matrix3.hh:176
double y
Y location.
Definition: Vector3.hh:336
The Vector3 class represents the generic vector containing 3 elements.
Definition: Vector3.hh:44
static const double GAZEBO_DEPRECATED(8.0) MAX_D
Double maximum value. This value will be similar to 1.79769e+308.
Definition: Helpers.hh:140
A 3x3 matrix class.
Definition: Matrix4.hh:40
friend Matrix3 operator*(double _s, const Matrix3 &_m)
Multiplication operators.
Definition: Matrix3.hh:133
Matrix3 operator*(const double &_s) const
returns the element wise scalar multiplication
Definition: Matrix3.hh:120
static const Matrix3 IDENTITY
Identity matrix.
Definition: Matrix3.hh:212
double z
Z location.
Definition: Vector3.hh:339
Matrix3 operator*(const Matrix3 &_m) const
Matrix multiplication operator.
Definition: Matrix3.hh:140
A 3x3 matrix class.
Definition: Matrix3.hh:40
math::Vector3 operator*(const math::Vector3 &_v) const
Matrix times Vector3 operator.
Definition: Matrix3.hh:165
double m[3][3]
the 3x3 matrix
Definition: Matrix3.hh:218
double * operator[](size_t _row)
Array subscript operator.
Definition: Matrix3.hh:185
Matrix3 operator+(const Matrix3 &_m) const
returns the element wise sum of two matrices
Definition: Matrix3.hh:110
friend std::ostream & operator<<(std::ostream &_out, const gazebo::math::Matrix3 &_m)
Stream insertion operator.
Definition: Matrix3.hh:196
Matrix3 operator-(const Matrix3 &_m) const
returns the element wise difference of two matrices
Definition: Matrix3.hh:100
static const Matrix3 ZERO
Zero matrix.
Definition: Matrix3.hh:215