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_Ax22d_HeaderFile
16 #define _gp_Ax22d_HeaderFile
17
18 #include <gp_Ax2d.hxx>
19 #include <gp_Dir2d.hxx>
20 #include <gp_Pnt2d.hxx>
21 #include <gp_Trsf2d.hxx>
22 #include <gp_Vec2d.hxx>
23 #include <Standard_ConstructionError.hxx>
24
25 //! Describes a coordinate system in a plane (2D space).
26 //! A coordinate system is defined by:
27 //! - its origin (also referred to as its "Location point"), and
28 //! - two orthogonal unit vectors, respectively, called the "X
29 //! Direction" and the "Y Direction".
30 //! A gp_Ax22d may be right-handed ("direct sense") or
31 //! left-handed ("inverse" or "indirect sense").
32 //! You use a gp_Ax22d to:
33 //! - describe 2D geometric entities, in particular to position
34 //! them. The local coordinate system of a geometric
35 //! entity serves for the same purpose as the STEP
36 //! function "axis placement two axes", or
37 //! - define geometric transformations.
38 //! Note: we refer to the "X Axis" and "Y Axis" as the axes having:
39 //! - the origin of the coordinate system as their origin, and
40 //! - the unit vectors "X Direction" and "Y Direction",
41 //! respectively, as their unit vectors.
42 class gp_Ax22d
43 {
44 public:
45
46 DEFINE_STANDARD_ALLOC
47
48 //! Creates an object representing the reference
49 //! coordinate system (OXY).
gp_Ax22d()50 gp_Ax22d() : vydir (0., 1.)
51 // vxdir(1.,0.) use default ctor of gp_Dir2d, as it creates the same dir(1, 0)
52 {}
53
54 //! Creates a coordinate system with origin theP and where:
55 //! - theVx is the "X Direction", and
56 //! - the "Y Direction" is orthogonal to theVx and
57 //! oriented so that the cross products theVx^"Y
58 //! Direction" and theVx^theVy have the same sign.
59 //! Raises ConstructionError if theVx and theVy are parallel (same or opposite orientation).
gp_Ax22d(const gp_Pnt2d & theP,const gp_Dir2d & theVx,const gp_Dir2d & theVy)60 gp_Ax22d (const gp_Pnt2d& theP, const gp_Dir2d& theVx, const gp_Dir2d& theVy)
61 : point (theP),
62 vydir (theVy),
63 vxdir (theVx)
64 {
65 Standard_Real aValue = theVx.Crossed (theVy);
66 if (aValue >= 0.0)
67 {
68 vydir.SetCoord (-vxdir.Y(), vxdir.X());
69 }
70 else
71 {
72 vydir.SetCoord (vxdir.Y(), -vxdir.X());
73 }
74 }
75
76 //! Creates - a coordinate system with origin theP and "X Direction"
77 //! theV, which is:
78 //! - right-handed if theIsSense is true (default value), or
79 //! - left-handed if theIsSense is false
gp_Ax22d(const gp_Pnt2d & theP,const gp_Dir2d & theV,const Standard_Boolean theIsSense=Standard_True)80 gp_Ax22d (const gp_Pnt2d& theP, const gp_Dir2d& theV, const Standard_Boolean theIsSense = Standard_True)
81 : point (theP),
82 vxdir (theV)
83 {
84 if (theIsSense)
85 {
86 vydir.SetCoord (-theV.Y(), theV.X());
87 }
88 else
89 {
90 vydir.SetCoord (theV.Y(), -theV.X());
91 }
92 }
93
94 //! Creates - a coordinate system where its origin is the origin of
95 //! theA and its "X Direction" is the unit vector of theA, which is:
96 //! - right-handed if theIsSense is true (default value), or
97 //! - left-handed if theIsSense is false.
gp_Ax22d(const gp_Ax2d & theA,const Standard_Boolean theIsSense=Standard_True)98 gp_Ax22d (const gp_Ax2d& theA, const Standard_Boolean theIsSense = Standard_True)
99 : point (theA.Location()),
100 vxdir (theA.Direction())
101 {
102 if (theIsSense)
103 {
104 vydir.SetCoord (-vxdir.Y(), vxdir.X());
105 }
106 else
107 {
108 vydir.SetCoord (vxdir.Y(), -vxdir.X());
109 }
110 }
111
112 //! Assigns the origin and the two unit vectors of the
113 //! coordinate system theA1 to this coordinate system.
SetAxis(const gp_Ax22d & theA1)114 void SetAxis (const gp_Ax22d& theA1)
115 {
116 point = theA1.Location();
117 vxdir = theA1.XDirection();
118 vydir = theA1.YDirection();
119 }
120
121 //! Changes the XAxis and YAxis ("Location" point and "Direction")
122 //! of <me>.
123 //! The "YDirection" is recomputed in the same sense as before.
124 void SetXAxis (const gp_Ax2d& theA1);
125
126 //! Changes the XAxis and YAxis ("Location" point and "Direction") of <me>.
127 //! The "XDirection" is recomputed in the same sense as before.
128 void SetYAxis (const gp_Ax2d& theA1);
129
130 //! Changes the "Location" point (origin) of <me>.
SetLocation(const gp_Pnt2d & theP)131 void SetLocation (const gp_Pnt2d& theP) { point = theP; }
132
133 //! Assigns theVx to the "X Direction" of
134 //! this coordinate system. The other unit vector of this
135 //! coordinate system is recomputed, normal to theVx ,
136 //! without modifying the orientation (right-handed or
137 //! left-handed) of this coordinate system.
138 void SetXDirection (const gp_Dir2d& theVx);
139
140 //! Assignsr theVy to the "Y Direction" of
141 //! this coordinate system. The other unit vector of this
142 //! coordinate system is recomputed, normal to theVy,
143 //! without modifying the orientation (right-handed or
144 //! left-handed) of this coordinate system.
145 void SetYDirection (const gp_Dir2d& theVy);
146
147 //! Returns an axis, for which
148 //! - the origin is that of this coordinate system, and
149 //! - the unit vector is either the "X Direction" of this coordinate system.
150 //! Note: the result is the "X Axis" of this coordinate system.
XAxis() const151 gp_Ax2d XAxis() const { return gp_Ax2d (point, vxdir); }
152
153 //! Returns an axis, for which
154 //! - the origin is that of this coordinate system, and
155 //! - the unit vector is either the "Y Direction" of this coordinate system.
156 //! Note: the result is the "Y Axis" of this coordinate system.
YAxis() const157 gp_Ax2d YAxis() const { return gp_Ax2d (point, vydir); }
158
159 //! Returns the "Location" point (origin) of <me>.
Location() const160 const gp_Pnt2d& Location() const { return point; }
161
162 //! Returns the "XDirection" of <me>.
XDirection() const163 const gp_Dir2d& XDirection() const { return vxdir; }
164
165 //! Returns the "YDirection" of <me>.
YDirection() const166 const gp_Dir2d& YDirection() const { return vydir; }
167
168 Standard_EXPORT void Mirror (const gp_Pnt2d& theP);
169
170 //! Performs the symmetrical transformation of an axis
171 //! placement with respect to the point theP which is the
172 //! center of the symmetry.
173 //! Warnings :
174 //! The main direction of the axis placement is not changed.
175 //! The "XDirection" and the "YDirection" are reversed.
176 //! So the axis placement stay right handed.
177 Standard_NODISCARD Standard_EXPORT gp_Ax22d Mirrored (const gp_Pnt2d& theP) const;
178
179 Standard_EXPORT void Mirror (const gp_Ax2d& theA);
180
181 //! Performs the symmetrical transformation of an axis
182 //! placement with respect to an axis placement which
183 //! is the axis of the symmetry.
184 //! The transformation is performed on the "Location"
185 //! point, on the "XDirection" and "YDirection".
186 //! The resulting main "Direction" is the cross product between
187 //! the "XDirection" and the "YDirection" after transformation.
188 Standard_NODISCARD Standard_EXPORT gp_Ax22d Mirrored (const gp_Ax2d& theA) const;
189
190 void Rotate (const gp_Pnt2d& theP, const Standard_Real theAng);
191
192 //! Rotates an axis placement. <theA1> is the axis of the
193 //! rotation . theAng is the angular value of the rotation
194 //! in radians.
Rotated(const gp_Pnt2d & theP,const Standard_Real theAng) const195 Standard_NODISCARD gp_Ax22d Rotated (const gp_Pnt2d& theP, const Standard_Real theAng) const
196 {
197 gp_Ax22d aTemp = *this;
198 aTemp.Rotate (theP, theAng);
199 return aTemp;
200 }
201
202 void Scale (const gp_Pnt2d& theP, const Standard_Real theS);
203
204 //! Applies a scaling transformation on the axis placement.
205 //! The "Location" point of the axisplacement is modified.
206 //! Warnings :
207 //! If the scale <theS> is negative :
208 //! . the main direction of the axis placement is not changed.
209 //! . The "XDirection" and the "YDirection" are reversed.
210 //! So the axis placement stay right handed.
Scaled(const gp_Pnt2d & theP,const Standard_Real theS) const211 Standard_NODISCARD gp_Ax22d Scaled (const gp_Pnt2d& theP, const Standard_Real theS) const
212 {
213 gp_Ax22d aTemp = *this;
214 aTemp.Scale (theP, theS);
215 return aTemp;
216 }
217
218 void Transform (const gp_Trsf2d& theT);
219
220 //! Transforms an axis placement with a Trsf.
221 //! The "Location" point, the "XDirection" and the
222 //! "YDirection" are transformed with theT. The resulting
223 //! main "Direction" of <me> is the cross product between
224 //! the "XDirection" and the "YDirection" after transformation.
Transformed(const gp_Trsf2d & theT) const225 Standard_NODISCARD gp_Ax22d Transformed (const gp_Trsf2d& theT) const
226 {
227 gp_Ax22d aTemp = *this;
228 aTemp.Transform (theT);
229 return aTemp;
230 }
231
Translate(const gp_Vec2d & theV)232 void Translate (const gp_Vec2d& theV) { point.Translate (theV); }
233
234 //! Translates an axis plaxement in the direction of the vector
235 //! <theV>. The magnitude of the translation is the vector's magnitude.
Translated(const gp_Vec2d & theV) const236 Standard_NODISCARD gp_Ax22d Translated (const gp_Vec2d& theV) const
237 {
238 gp_Ax22d aTemp = *this;
239 aTemp.Translate (theV);
240 return aTemp;
241 }
242
Translate(const gp_Pnt2d & theP1,const gp_Pnt2d & theP2)243 void Translate (const gp_Pnt2d& theP1, const gp_Pnt2d& theP2) { point.Translate (theP1, theP2); }
244
245 //! Translates an axis placement from the point <theP1> to the
246 //! point <theP2>.
Translated(const gp_Pnt2d & theP1,const gp_Pnt2d & theP2) const247 Standard_NODISCARD gp_Ax22d Translated (const gp_Pnt2d& theP1, const gp_Pnt2d& theP2) const
248 {
249 gp_Ax22d aTemp = *this;
250 aTemp.Translate (theP1, theP2);
251 return aTemp;
252 }
253
254 //! Dumps the content of me into the stream
255 Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
256
257 private:
258
259 gp_Pnt2d point;
260 gp_Dir2d vydir;
261 gp_Dir2d vxdir;
262
263 };
264
265 // =======================================================================
266 // function : SetDirection
267 // purpose :
268 // =======================================================================
SetXAxis(const gp_Ax2d & theA1)269 inline void gp_Ax22d::SetXAxis (const gp_Ax2d& theA1)
270 {
271 Standard_Boolean isSign = (vxdir.Crossed(vydir)) >= 0.0;
272 point = theA1.Location ();
273 vxdir = theA1.Direction();
274 if (isSign)
275 {
276 vydir.SetCoord (-vxdir.Y(), vxdir.X());
277 }
278 else
279 {
280 vydir.SetCoord (vxdir.Y(), -vxdir.X());
281 }
282 }
283
284 // =======================================================================
285 // function : SetDirection
286 // purpose :
287 // =======================================================================
SetYAxis(const gp_Ax2d & theA1)288 inline void gp_Ax22d::SetYAxis (const gp_Ax2d& theA1)
289 {
290 Standard_Boolean isSign = (vxdir.Crossed(vydir)) >= 0.0;
291 point = theA1.Location ();
292 vydir = theA1.Direction();
293 if (isSign)
294 {
295 vxdir.SetCoord (vydir.Y(), -vydir.X());
296 }
297 else
298 {
299 vxdir.SetCoord (-vydir.Y(), vydir.X());
300 }
301 }
302
303 // =======================================================================
304 // function : SetXDirection
305 // purpose :
306 // =======================================================================
SetXDirection(const gp_Dir2d & theVx)307 inline void gp_Ax22d::SetXDirection (const gp_Dir2d& theVx)
308 {
309 Standard_Boolean isSign = (vxdir.Crossed(vydir)) >= 0.0;
310 vxdir = theVx;
311 if (isSign)
312 {
313 vydir.SetCoord (-theVx.Y(), theVx.X());
314 }
315 else
316 {
317 vydir.SetCoord (theVx.Y(), -theVx.X());
318 }
319 }
320
321 // =======================================================================
322 // function : SetYDirection
323 // purpose :
324 // =======================================================================
SetYDirection(const gp_Dir2d & theVy)325 inline void gp_Ax22d::SetYDirection (const gp_Dir2d& theVy)
326 {
327 Standard_Boolean isSign = (vxdir.Crossed(vydir)) >= 0.0;
328 vydir = theVy;
329 if (isSign)
330 {
331 vxdir.SetCoord (theVy.Y(), -theVy.X());
332 }
333 else
334 {
335 vxdir.SetCoord (-theVy.Y(), theVy.X());
336 }
337 }
338
339 // =======================================================================
340 // function : Rotate
341 // purpose :
342 // =======================================================================
Rotate(const gp_Pnt2d & theP,const Standard_Real theAng)343 inline void gp_Ax22d::Rotate (const gp_Pnt2d& theP, const Standard_Real theAng)
344 {
345 gp_Pnt2d aTemp = point;
346 aTemp.Rotate (theP, theAng);
347 point = aTemp;
348 vxdir.Rotate (theAng);
349 vydir.Rotate (theAng);
350 }
351
352 // =======================================================================
353 // function : Scale
354 // purpose :
355 // =======================================================================
Scale(const gp_Pnt2d & theP,const Standard_Real theS)356 inline void gp_Ax22d::Scale (const gp_Pnt2d& theP, const Standard_Real theS)
357 {
358 gp_Pnt2d aTemp = point;
359 aTemp.Scale (theP, theS);
360 point = aTemp;
361 if (theS < 0.0)
362 {
363 vxdir.Reverse();
364 vydir.Reverse();
365 }
366 }
367
368 // =======================================================================
369 // function : Transform
370 // purpose :
371 // =======================================================================
Transform(const gp_Trsf2d & theT)372 inline void gp_Ax22d::Transform (const gp_Trsf2d& theT)
373 {
374 gp_Pnt2d aTemp = point;
375 aTemp.Transform (theT);
376 point = aTemp;
377 vxdir.Transform (theT);
378 vydir.Transform (theT);
379 }
380
381 #endif // _gp_Ax22d_HeaderFile
382