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_Trsf2d_HeaderFile
16 #define _gp_Trsf2d_HeaderFile
18 #include <Standard.hxx>
19 #include <Standard_DefineAlloc.hxx>
20 #include <Standard_Handle.hxx>
22 #include <Standard_Real.hxx>
23 #include <gp_TrsfForm.hxx>
24 #include <gp_Mat2d.hxx>
26 #include <Standard_Boolean.hxx>
27 #include <Standard_Integer.hxx>
28 class Standard_ConstructionError;
29 class Standard_OutOfRange;
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 :
49 //! | a11 a12 a13 | | x | | x'|
50 //! | a21 a22 a23 | | y | | y'|
51 //! | 0 0 1 | | 1 | | 1 |
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.
63 //! Returns identity transformation.
66 //! Creates a 2d transformation in the XY plane from a
67 //! 3d transformation .
68 gp_Trsf2d(const gp_Trsf& T);
71 //! Changes the transformation into a symmetrical transformation.
72 //! P is the center of the symmetry.
73 void SetMirror (const gp_Pnt2d& P);
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);
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);
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);
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);
97 //! Changes the transformation allowing passage from the basic
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);
104 //! Changes the transformation into a translation.
105 //! V is the vector of the translation.
106 void SetTranslation (const gp_Vec2d& V);
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);
113 //! Replaces the translation vector with V.
114 Standard_EXPORT void SetTranslationPart (const gp_Vec2d& V);
116 //! Modifies the scale factor.
117 Standard_EXPORT void SetScaleFactor (const Standard_Real S);
119 //! Returns true if the determinant of the vectorial part of
120 //! this transformation is negative..
121 Standard_Boolean IsNegative() const;
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;
130 //! Returns the scale factor.
131 Standard_Real ScaleFactor() const;
134 //! Returns the translation part of the transformation's matrix
135 const gp_XY& TranslationPart() const;
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;
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;
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;
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;
160 Standard_EXPORT void Invert();
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;
169 Standard_NODISCARD gp_Trsf2d Multiplied (const gp_Trsf2d& T) const;
170 Standard_NODISCARD gp_Trsf2d operator * (const gp_Trsf2d& T) const
172 return Multiplied(T);
176 //! Computes the transformation composed from <me> and T.
178 Standard_EXPORT void Multiply (const gp_Trsf2d& T);
179 void operator *= (const gp_Trsf2d& T)
185 //! Computes the transformation composed from <me> and T.
187 Standard_EXPORT void PreMultiply (const gp_Trsf2d& T);
189 Standard_EXPORT void Power (const Standard_Integer N);
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().
197 //! Raises if N < 0 and if the matrix of the transformation not
199 gp_Trsf2d Powered (const Standard_Integer N);
201 void Transforms (Standard_Real& X, Standard_Real& Y) const;
203 //! Transforms a doublet XY with a Trsf2d
204 void Transforms (gp_XY& Coord) const;
206 //! Sets the coefficients of the transformation. The
207 //! transformation of the point x,y is the point
210 //! x' = a11 x + a12 y + a13
211 //! y' = a21 x + a22 y + a23
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);
219 friend class gp_GTrsf2d;
225 //! Makes orthogonalization of "matrix"
226 Standard_EXPORT void Orthogonalize();
244 #include <gp_Trsf2d.lxx>
250 #endif // _gp_Trsf2d_HeaderFile