1 // Copyright (c) 1991-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #ifndef _gp_Mat_HeaderFile
16 #define _gp_Mat_HeaderFile
18 #include <Standard.hxx>
19 #include <Standard_DefineAlloc.hxx>
20 #include <Standard_Handle.hxx>
22 #include <Standard_Real.hxx>
23 #include <Standard_Integer.hxx>
24 #include <Standard_Boolean.hxx>
25 class Standard_ConstructionError;
26 class Standard_OutOfRange;
33 //! Describes a three column, three row matrix. This sort of
34 //! object is used in various vectorial or matrix computations.
42 //! creates a matrix with null coefficients.
45 gp_Mat(const Standard_Real a11, const Standard_Real a12, const Standard_Real a13, const Standard_Real a21, const Standard_Real a22, const Standard_Real a23, const Standard_Real a31, const Standard_Real a32, const Standard_Real a33);
48 //! Col1, Col2, Col3 are the 3 columns of the matrix.
49 Standard_EXPORT gp_Mat(const gp_XYZ& Col1, const gp_XYZ& Col2, const gp_XYZ& Col3);
51 //! Assigns the three coordinates of Value to the column of index
52 //! Col of this matrix.
53 //! Raises OutOfRange if Col < 1 or Col > 3.
54 Standard_EXPORT void SetCol (const Standard_Integer Col, const gp_XYZ& Value);
56 //! Assigns the number triples Col1, Col2, Col3 to the three
57 //! columns of this matrix.
58 Standard_EXPORT void SetCols (const gp_XYZ& Col1, const gp_XYZ& Col2, const gp_XYZ& Col3);
61 //! Modifies the matrix M so that applying it to any number
62 //! triple (X, Y, Z) produces the same result as the cross
63 //! product of Ref and the number triple (X, Y, Z):
64 //! i.e.: M * {X,Y,Z}t = Ref.Cross({X, Y ,Z})
65 //! this matrix is anti symmetric. To apply this matrix to the
66 //! triplet {XYZ} is the same as to do the cross product between the
67 //! triplet Ref and the triplet {XYZ}.
68 //! Note: this matrix is anti-symmetric.
69 Standard_EXPORT void SetCross (const gp_XYZ& Ref);
72 //! Modifies the main diagonal of the matrix.
73 //! <me>.Value (1, 1) = X1
74 //! <me>.Value (2, 2) = X2
75 //! <me>.Value (3, 3) = X3
76 //! The other coefficients of the matrix are not modified.
77 void SetDiagonal (const Standard_Real X1, const Standard_Real X2, const Standard_Real X3);
80 //! Modifies this matrix so that applying it to any number
81 //! triple (X, Y, Z) produces the same result as the scalar
82 //! product of Ref and the number triple (X, Y, Z):
83 //! this * (X,Y,Z) = Ref.(X,Y,Z)
84 //! Note: this matrix is symmetric.
85 Standard_EXPORT void SetDot (const gp_XYZ& Ref);
87 //! Modifies this matrix so that it represents the Identity matrix.
91 //! Modifies this matrix so that it represents a rotation. Ang is the angular value in
92 //! radians and the XYZ axis gives the direction of the
94 //! Raises ConstructionError if XYZ.Modulus() <= Resolution()
95 Standard_EXPORT void SetRotation (const gp_XYZ& Axis, const Standard_Real Ang);
97 //! Assigns the three coordinates of Value to the row of index
98 //! Row of this matrix. Raises OutOfRange if Row < 1 or Row > 3.
99 Standard_EXPORT void SetRow (const Standard_Integer Row, const gp_XYZ& Value);
101 //! Assigns the number triples Row1, Row2, Row3 to the three
102 //! rows of this matrix.
103 Standard_EXPORT void SetRows (const gp_XYZ& Row1, const gp_XYZ& Row2, const gp_XYZ& Row3);
106 //! Modifies the the matrix so that it represents
107 //! a scaling transformation, where S is the scale factor. :
109 //! <me> = | 0.0 S 0.0 |
111 void SetScale (const Standard_Real S);
113 //! Assigns <Value> to the coefficient of row Row, column Col of this matrix.
114 //! Raises OutOfRange if Row < 1 or Row > 3 or Col < 1 or Col > 3
115 void SetValue (const Standard_Integer Row, const Standard_Integer Col, const Standard_Real Value);
117 //! Returns the column of Col index.
118 //! Raises OutOfRange if Col < 1 or Col > 3
119 Standard_EXPORT gp_XYZ Column (const Standard_Integer Col) const;
121 //! Computes the determinant of the matrix.
122 Standard_Real Determinant() const;
124 //! Returns the main diagonal of the matrix.
125 Standard_EXPORT gp_XYZ Diagonal() const;
127 //! returns the row of Row index.
128 //! Raises OutOfRange if Row < 1 or Row > 3
129 Standard_EXPORT gp_XYZ Row (const Standard_Integer Row) const;
131 //! Returns the coefficient of range (Row, Col)
132 //! Raises OutOfRange if Row < 1 or Row > 3 or Col < 1 or Col > 3
133 const Standard_Real& Value (const Standard_Integer Row, const Standard_Integer Col) const;
134 const Standard_Real& operator() (const Standard_Integer Row, const Standard_Integer Col) const
136 return Value(Row,Col);
139 //! Returns the coefficient of range (Row, Col)
140 //! Raises OutOfRange if Row < 1 or Row > 3 or Col < 1 or Col > 3
141 Standard_Real& ChangeValue (const Standard_Integer Row, const Standard_Integer Col);
142 Standard_Real& operator() (const Standard_Integer Row, const Standard_Integer Col)
144 return ChangeValue(Row,Col);
148 //! The Gauss LU decomposition is used to invert the matrix
149 //! (see Math package) so the matrix is considered as singular if
150 //! the largest pivot found is lower or equal to Resolution from gp.
151 Standard_Boolean IsSingular() const;
153 void Add (const gp_Mat& Other);
154 void operator += (const gp_Mat& Other)
159 //! Computes the sum of this matrix and
160 //! the matrix Other for each coefficient of the matrix :
161 //! <me>.Coef(i,j) + <Other>.Coef(i,j)
162 Standard_NODISCARD gp_Mat Added (const gp_Mat& Other) const;
163 Standard_NODISCARD gp_Mat operator + (const gp_Mat& Other) const
168 void Divide (const Standard_Real Scalar);
169 void operator /= (const Standard_Real Scalar)
174 //! Divides all the coefficients of the matrix by Scalar
175 Standard_NODISCARD gp_Mat Divided (const Standard_Real Scalar) const;
176 Standard_NODISCARD gp_Mat operator / (const Standard_Real Scalar) const
178 return Divided(Scalar);
181 Standard_EXPORT void Invert();
184 //! Inverses the matrix and raises if the matrix is singular.
185 //! - Invert assigns the result to this matrix, while
186 //! - Inverted creates a new one.
188 //! The Gauss LU decomposition is used to invert the matrix.
189 //! Consequently, the matrix is considered as singular if the
190 //! largest pivot found is less than or equal to gp::Resolution().
192 //! Standard_ConstructionError if this matrix is singular,
193 //! and therefore cannot be inverted.
194 Standard_NODISCARD Standard_EXPORT gp_Mat Inverted() const;
197 //! Computes the product of two matrices <me> * <Other>
198 Standard_NODISCARD gp_Mat Multiplied (const gp_Mat& Other) const;
199 Standard_NODISCARD gp_Mat operator * (const gp_Mat& Other) const
201 return Multiplied(Other);
204 //! Computes the product of two matrices <me> = <Other> * <me>.
205 void Multiply (const gp_Mat& Other);
206 void operator *= (const gp_Mat& Other)
211 void PreMultiply (const gp_Mat& Other);
213 Standard_NODISCARD gp_Mat Multiplied (const Standard_Real Scalar) const;
214 Standard_NODISCARD gp_Mat operator * (const Standard_Real Scalar) const
216 return Multiplied(Scalar);
220 //! Multiplies all the coefficients of the matrix by Scalar
221 void Multiply (const Standard_Real Scalar);
222 void operator *= (const Standard_Real Scalar)
227 Standard_EXPORT void Power (const Standard_Integer N);
230 //! Computes <me> = <me> * <me> * .......* <me>, N time.
231 //! if N = 0 <me> = Identity
232 //! if N < 0 <me> = <me>.Invert() *...........* <me>.Invert().
233 //! If N < 0 an exception will be raised if the matrix is not
235 Standard_NODISCARD gp_Mat Powered (const Standard_Integer N) const;
237 void Subtract (const gp_Mat& Other);
238 void operator -= (const gp_Mat& Other)
244 //! cOmputes for each coefficient of the matrix :
245 //! <me>.Coef(i,j) - <Other>.Coef(i,j)
246 Standard_NODISCARD gp_Mat Subtracted (const gp_Mat& Other) const;
247 Standard_NODISCARD gp_Mat operator - (const gp_Mat& Other) const
249 return Subtracted(Other);
255 //! Transposes the matrix. A(j, i) -> A (i, j)
256 Standard_NODISCARD gp_Mat Transposed() const;
260 friend class gp_Trsf;
261 friend class gp_GTrsf;
274 Standard_Real matrix[3][3];
280 #include <gp_Mat.lxx>
286 #endif // _gp_Mat_HeaderFile