99033bf246550086fac0ecea8342358b2d57367e
[occt.git] / src / gp / gp_Trsf2d.hxx
1 // Copyright (c) 1991-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
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.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15 #ifndef _gp_Trsf2d_HeaderFile
16 #define _gp_Trsf2d_HeaderFile
17
18 #include <Standard.hxx>
19 #include <Standard_DefineAlloc.hxx>
20 #include <Standard_Handle.hxx>
21
22 #include <Standard_Real.hxx>
23 #include <gp_TrsfForm.hxx>
24 #include <gp_Mat2d.hxx>
25 #include <gp_XY.hxx>
26 #include <Standard_Boolean.hxx>
27 #include <Standard_Integer.hxx>
28 class Standard_ConstructionError;
29 class Standard_OutOfRange;
30 class gp_GTrsf2d;
31 class gp_Trsf;
32 class gp_Pnt2d;
33 class gp_Ax2d;
34 class gp_Vec2d;
35 class gp_XY;
36 class gp_Mat2d;
37
38
39
40 //! Defines a non-persistent transformation in 2D space.
41 //! The following transformations are implemented :
42 //! - Translation, Rotation, Scale
43 //! - Symmetry with respect to a point and a line.
44 //! Complex transformations can be obtained by combining the
45 //! previous elementary transformations using the method Multiply.
46 //! The transformations can be represented as follow :
47 //! @code
48 //!    V1   V2   T       XY        XY
49 //! | a11  a12  a13 |   | x |     | x'|
50 //! | a21  a22  a23 |   | y |     | y'|
51 //! |  0    0    1  |   | 1 |     | 1 |
52 //! @endcode
53 //! where {V1, V2} defines the vectorial part of the transformation
54 //! and T defines the translation part of the transformation.
55 //! This transformation never change the nature of the objects.
56 class gp_Trsf2d 
57 {
58 public:
59
60   DEFINE_STANDARD_ALLOC
61
62   
63   //! Returns identity transformation.
64     gp_Trsf2d();
65   
66   //! Creates a 2d transformation in the XY plane from a
67   //! 3d transformation .
68     gp_Trsf2d(const gp_Trsf& T);
69   
70
71   //! Changes the transformation into a symmetrical transformation.
72   //! P is the center of the symmetry.
73     void SetMirror (const gp_Pnt2d& P);
74   
75
76   //! Changes the transformation into a symmetrical transformation.
77   //! A is the center of the axial symmetry.
78   Standard_EXPORT void SetMirror (const gp_Ax2d& A);
79   
80
81   //! Changes the transformation into a rotation.
82   //! P is the rotation's center and Ang is the angular value of the
83   //! rotation in radian.
84     void SetRotation (const gp_Pnt2d& P, const Standard_Real Ang);
85   
86
87   //! Changes the transformation into a scale.
88   //! P is the center of the scale and S is the scaling value.
89     void SetScale (const gp_Pnt2d& P, const Standard_Real S);
90   
91
92   //! Changes a transformation allowing passage from the coordinate
93   //! system "FromSystem1" to the coordinate system "ToSystem2".
94   Standard_EXPORT void SetTransformation (const gp_Ax2d& FromSystem1, const gp_Ax2d& ToSystem2);
95   
96
97   //! Changes the transformation allowing passage from the basic
98   //! coordinate system
99   //! {P(0.,0.,0.), VX (1.,0.,0.), VY (0.,1.,0.)}
100   //! to the local coordinate system defined with the Ax2d ToSystem.
101   Standard_EXPORT void SetTransformation (const gp_Ax2d& ToSystem);
102   
103
104   //! Changes the transformation into a translation.
105   //! V is the vector of the translation.
106     void SetTranslation (const gp_Vec2d& V);
107   
108
109   //! Makes the transformation into a translation from
110   //! the point P1 to the point P2.
111     void SetTranslation (const gp_Pnt2d& P1, const gp_Pnt2d& P2);
112   
113   //! Replaces the translation vector with V.
114   Standard_EXPORT void SetTranslationPart (const gp_Vec2d& V);
115   
116   //! Modifies the scale factor.
117   Standard_EXPORT void SetScaleFactor (const Standard_Real S);
118   
119   //! Returns true if the determinant of the vectorial part of
120   //! this transformation is negative..
121     Standard_Boolean IsNegative() const;
122   
123
124   //! Returns the nature of the transformation. It can be  an
125   //! identity transformation, a rotation, a translation, a mirror
126   //! (relative to a point or an axis), a scaling transformation,
127   //! or a compound transformation.
128     gp_TrsfForm Form() const;
129   
130   //! Returns the scale factor.
131     Standard_Real ScaleFactor() const;
132   
133
134   //! Returns the translation part of the transformation's matrix
135     const gp_XY& TranslationPart() const;
136   
137
138   //! Returns the vectorial part of the transformation. It is a
139   //! 2*2 matrix which includes the scale factor.
140   Standard_EXPORT gp_Mat2d VectorialPart() const;
141   
142
143   //! Returns the homogeneous vectorial part of the transformation.
144   //! It is a 2*2 matrix which doesn't include the scale factor.
145   //! The coefficients of this matrix must be multiplied by the
146   //! scale factor to obtain the coefficients of the transformation.
147     const gp_Mat2d& HVectorialPart() const;
148   
149
150   //! Returns the angle corresponding to the rotational component
151   //! of the transformation matrix (operation opposite to SetRotation()).
152   Standard_EXPORT Standard_Real RotationPart() const;
153   
154
155   //! Returns the coefficients of the transformation's matrix.
156   //! It is a 2 rows * 3 columns matrix.
157   //! Raises OutOfRange if Row < 1 or Row > 2 or Col < 1 or Col > 3
158     Standard_Real Value (const Standard_Integer Row, const Standard_Integer Col) const;
159   
160   Standard_EXPORT void Invert();
161   
162
163   //! Computes the reverse transformation.
164   //! Raises an exception if the matrix of the transformation
165   //! is not inversible, it means that the scale factor is lower
166   //! or equal to Resolution from package gp.
167   Standard_NODISCARD gp_Trsf2d Inverted() const;
168   
169   Standard_NODISCARD gp_Trsf2d Multiplied (const gp_Trsf2d& T) const;
170   Standard_NODISCARD gp_Trsf2d operator * (const gp_Trsf2d& T) const
171 {
172   return Multiplied(T);
173 }
174   
175
176   //! Computes the transformation composed from <me> and T.
177   //! <me> = <me> * T
178   Standard_EXPORT void Multiply (const gp_Trsf2d& T);
179 void operator *= (const gp_Trsf2d& T)
180 {
181   Multiply(T);
182 }
183   
184
185   //! Computes the transformation composed from <me> and T.
186   //! <me> = T * <me>
187   Standard_EXPORT void PreMultiply (const gp_Trsf2d& T);
188   
189   Standard_EXPORT void Power (const Standard_Integer N);
190   
191
192   //! Computes the following composition of transformations
193   //! <me> * <me> * .......* <me>,  N time.
194   //! if N = 0 <me> = Identity
195   //! if N < 0 <me> = <me>.Inverse() *...........* <me>.Inverse().
196   //!
197   //! Raises if N < 0 and if the matrix of the transformation not
198   //! inversible.
199     gp_Trsf2d Powered (const Standard_Integer N);
200   
201     void Transforms (Standard_Real& X, Standard_Real& Y) const;
202   
203   //! Transforms  a doublet XY with a Trsf2d
204     void Transforms (gp_XY& Coord) const;
205   
206   //! Sets the coefficients  of the transformation. The
207   //! transformation  of the  point  x,y is  the point
208   //! x',y' with :
209   //! @code
210   //! x' = a11 x + a12 y + a13
211   //! y' = a21 x + a22 y + a23
212   //! @endcode
213   //! The method Value(i,j) will return aij.
214   //! Raises ConstructionError if the determinant of the aij is null.
215   //! If the matrix as not a uniform scale it will be orthogonalized before future using.
216   Standard_EXPORT void SetValues (const Standard_Real a11, const Standard_Real a12, const Standard_Real a13, const Standard_Real a21, const Standard_Real a22, const Standard_Real a23);
217
218
219 friend class gp_GTrsf2d;
220
221
222 protected:
223
224   
225   //! Makes orthogonalization of "matrix"
226   Standard_EXPORT void Orthogonalize();
227
228
229
230
231 private:
232
233
234
235   Standard_Real scale;
236   gp_TrsfForm shape;
237   gp_Mat2d matrix;
238   gp_XY loc;
239
240
241 };
242
243
244 #include <gp_Trsf2d.lxx>
245
246
247
248
249
250 #endif // _gp_Trsf2d_HeaderFile