|
||||
File indexing completed on 2025-01-18 10:03:43
0001 // Copyright (c) 1991-1999 Matra Datavision 0002 // Copyright (c) 1999-2014 OPEN CASCADE SAS 0003 // 0004 // This file is part of Open CASCADE Technology software library. 0005 // 0006 // This library is free software; you can redistribute it and/or modify it under 0007 // the terms of the GNU Lesser General Public License version 2.1 as published 0008 // by the Free Software Foundation, with special exception defined in the file 0009 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT 0010 // distribution for complete text of the license and disclaimer of any warranty. 0011 // 0012 // Alternatively, this file may be used under the terms of Open CASCADE 0013 // commercial license or contractual agreement. 0014 0015 #ifndef _gp_Ax22d_HeaderFile 0016 #define _gp_Ax22d_HeaderFile 0017 0018 #include <gp_Ax2d.hxx> 0019 #include <gp_Dir2d.hxx> 0020 #include <gp_Pnt2d.hxx> 0021 #include <gp_Trsf2d.hxx> 0022 #include <gp_Vec2d.hxx> 0023 0024 //! Describes a coordinate system in a plane (2D space). 0025 //! A coordinate system is defined by: 0026 //! - its origin (also referred to as its "Location point"), and 0027 //! - two orthogonal unit vectors, respectively, called the "X 0028 //! Direction" and the "Y Direction". 0029 //! A gp_Ax22d may be right-handed ("direct sense") or 0030 //! left-handed ("inverse" or "indirect sense"). 0031 //! You use a gp_Ax22d to: 0032 //! - describe 2D geometric entities, in particular to position 0033 //! them. The local coordinate system of a geometric 0034 //! entity serves for the same purpose as the STEP 0035 //! function "axis placement two axes", or 0036 //! - define geometric transformations. 0037 //! Note: we refer to the "X Axis" and "Y Axis" as the axes having: 0038 //! - the origin of the coordinate system as their origin, and 0039 //! - the unit vectors "X Direction" and "Y Direction", 0040 //! respectively, as their unit vectors. 0041 class gp_Ax22d 0042 { 0043 public: 0044 0045 DEFINE_STANDARD_ALLOC 0046 0047 //! Creates an object representing the reference 0048 //! coordinate system (OXY). 0049 gp_Ax22d() : vydir (0., 1.) 0050 // vxdir(1.,0.) use default ctor of gp_Dir2d, as it creates the same dir(1, 0) 0051 {} 0052 0053 //! Creates a coordinate system with origin theP and where: 0054 //! - theVx is the "X Direction", and 0055 //! - the "Y Direction" is orthogonal to theVx and 0056 //! oriented so that the cross products theVx^"Y 0057 //! Direction" and theVx^theVy have the same sign. 0058 //! Raises ConstructionError if theVx and theVy are parallel (same or opposite orientation). 0059 gp_Ax22d (const gp_Pnt2d& theP, const gp_Dir2d& theVx, const gp_Dir2d& theVy) 0060 : point (theP), 0061 vydir (theVy), 0062 vxdir (theVx) 0063 { 0064 Standard_Real aValue = theVx.Crossed (theVy); 0065 if (aValue >= 0.0) 0066 { 0067 vydir.SetCoord (-vxdir.Y(), vxdir.X()); 0068 } 0069 else 0070 { 0071 vydir.SetCoord (vxdir.Y(), -vxdir.X()); 0072 } 0073 } 0074 0075 //! Creates - a coordinate system with origin theP and "X Direction" 0076 //! theV, which is: 0077 //! - right-handed if theIsSense is true (default value), or 0078 //! - left-handed if theIsSense is false 0079 gp_Ax22d (const gp_Pnt2d& theP, const gp_Dir2d& theV, const Standard_Boolean theIsSense = Standard_True) 0080 : point (theP), 0081 vxdir (theV) 0082 { 0083 if (theIsSense) 0084 { 0085 vydir.SetCoord (-theV.Y(), theV.X()); 0086 } 0087 else 0088 { 0089 vydir.SetCoord (theV.Y(), -theV.X()); 0090 } 0091 } 0092 0093 //! Creates - a coordinate system where its origin is the origin of 0094 //! theA and its "X Direction" is the unit vector of theA, which is: 0095 //! - right-handed if theIsSense is true (default value), or 0096 //! - left-handed if theIsSense is false. 0097 gp_Ax22d (const gp_Ax2d& theA, const Standard_Boolean theIsSense = Standard_True) 0098 : point (theA.Location()), 0099 vxdir (theA.Direction()) 0100 { 0101 if (theIsSense) 0102 { 0103 vydir.SetCoord (-vxdir.Y(), vxdir.X()); 0104 } 0105 else 0106 { 0107 vydir.SetCoord (vxdir.Y(), -vxdir.X()); 0108 } 0109 } 0110 0111 //! Assigns the origin and the two unit vectors of the 0112 //! coordinate system theA1 to this coordinate system. 0113 void SetAxis (const gp_Ax22d& theA1) 0114 { 0115 point = theA1.Location(); 0116 vxdir = theA1.XDirection(); 0117 vydir = theA1.YDirection(); 0118 } 0119 0120 //! Changes the XAxis and YAxis ("Location" point and "Direction") 0121 //! of <me>. 0122 //! The "YDirection" is recomputed in the same sense as before. 0123 void SetXAxis (const gp_Ax2d& theA1); 0124 0125 //! Changes the XAxis and YAxis ("Location" point and "Direction") of <me>. 0126 //! The "XDirection" is recomputed in the same sense as before. 0127 void SetYAxis (const gp_Ax2d& theA1); 0128 0129 //! Changes the "Location" point (origin) of <me>. 0130 void SetLocation (const gp_Pnt2d& theP) { point = theP; } 0131 0132 //! Assigns theVx to the "X Direction" of 0133 //! this coordinate system. The other unit vector of this 0134 //! coordinate system is recomputed, normal to theVx , 0135 //! without modifying the orientation (right-handed or 0136 //! left-handed) of this coordinate system. 0137 void SetXDirection (const gp_Dir2d& theVx); 0138 0139 //! Assignsr theVy to the "Y Direction" of 0140 //! this coordinate system. The other unit vector of this 0141 //! coordinate system is recomputed, normal to theVy, 0142 //! without modifying the orientation (right-handed or 0143 //! left-handed) of this coordinate system. 0144 void SetYDirection (const gp_Dir2d& theVy); 0145 0146 //! Returns an axis, for which 0147 //! - the origin is that of this coordinate system, and 0148 //! - the unit vector is either the "X Direction" of this coordinate system. 0149 //! Note: the result is the "X Axis" of this coordinate system. 0150 gp_Ax2d XAxis() const { return gp_Ax2d (point, vxdir); } 0151 0152 //! Returns an axis, for which 0153 //! - the origin is that of this coordinate system, and 0154 //! - the unit vector is either the "Y Direction" of this coordinate system. 0155 //! Note: the result is the "Y Axis" of this coordinate system. 0156 gp_Ax2d YAxis() const { return gp_Ax2d (point, vydir); } 0157 0158 //! Returns the "Location" point (origin) of <me>. 0159 const gp_Pnt2d& Location() const { return point; } 0160 0161 //! Returns the "XDirection" of <me>. 0162 const gp_Dir2d& XDirection() const { return vxdir; } 0163 0164 //! Returns the "YDirection" of <me>. 0165 const gp_Dir2d& YDirection() const { return vydir; } 0166 0167 Standard_EXPORT void Mirror (const gp_Pnt2d& theP); 0168 0169 //! Performs the symmetrical transformation of an axis 0170 //! placement with respect to the point theP which is the 0171 //! center of the symmetry. 0172 //! Warnings : 0173 //! The main direction of the axis placement is not changed. 0174 //! The "XDirection" and the "YDirection" are reversed. 0175 //! So the axis placement stay right handed. 0176 Standard_NODISCARD Standard_EXPORT gp_Ax22d Mirrored (const gp_Pnt2d& theP) const; 0177 0178 Standard_EXPORT void Mirror (const gp_Ax2d& theA); 0179 0180 //! Performs the symmetrical transformation of an axis 0181 //! placement with respect to an axis placement which 0182 //! is the axis of the symmetry. 0183 //! The transformation is performed on the "Location" 0184 //! point, on the "XDirection" and "YDirection". 0185 //! The resulting main "Direction" is the cross product between 0186 //! the "XDirection" and the "YDirection" after transformation. 0187 Standard_NODISCARD Standard_EXPORT gp_Ax22d Mirrored (const gp_Ax2d& theA) const; 0188 0189 void Rotate (const gp_Pnt2d& theP, const Standard_Real theAng); 0190 0191 //! Rotates an axis placement. <theA1> is the axis of the 0192 //! rotation . theAng is the angular value of the rotation 0193 //! in radians. 0194 Standard_NODISCARD gp_Ax22d Rotated (const gp_Pnt2d& theP, const Standard_Real theAng) const 0195 { 0196 gp_Ax22d aTemp = *this; 0197 aTemp.Rotate (theP, theAng); 0198 return aTemp; 0199 } 0200 0201 void Scale (const gp_Pnt2d& theP, const Standard_Real theS); 0202 0203 //! Applies a scaling transformation on the axis placement. 0204 //! The "Location" point of the axisplacement is modified. 0205 //! Warnings : 0206 //! If the scale <theS> is negative : 0207 //! . the main direction of the axis placement is not changed. 0208 //! . The "XDirection" and the "YDirection" are reversed. 0209 //! So the axis placement stay right handed. 0210 Standard_NODISCARD gp_Ax22d Scaled (const gp_Pnt2d& theP, const Standard_Real theS) const 0211 { 0212 gp_Ax22d aTemp = *this; 0213 aTemp.Scale (theP, theS); 0214 return aTemp; 0215 } 0216 0217 void Transform (const gp_Trsf2d& theT); 0218 0219 //! Transforms an axis placement with a Trsf. 0220 //! The "Location" point, the "XDirection" and the 0221 //! "YDirection" are transformed with theT. The resulting 0222 //! main "Direction" of <me> is the cross product between 0223 //! the "XDirection" and the "YDirection" after transformation. 0224 Standard_NODISCARD gp_Ax22d Transformed (const gp_Trsf2d& theT) const 0225 { 0226 gp_Ax22d aTemp = *this; 0227 aTemp.Transform (theT); 0228 return aTemp; 0229 } 0230 0231 void Translate (const gp_Vec2d& theV) { point.Translate (theV); } 0232 0233 //! Translates an axis plaxement in the direction of the vector 0234 //! <theV>. The magnitude of the translation is the vector's magnitude. 0235 Standard_NODISCARD gp_Ax22d Translated (const gp_Vec2d& theV) const 0236 { 0237 gp_Ax22d aTemp = *this; 0238 aTemp.Translate (theV); 0239 return aTemp; 0240 } 0241 0242 void Translate (const gp_Pnt2d& theP1, const gp_Pnt2d& theP2) { point.Translate (theP1, theP2); } 0243 0244 //! Translates an axis placement from the point <theP1> to the 0245 //! point <theP2>. 0246 Standard_NODISCARD gp_Ax22d Translated (const gp_Pnt2d& theP1, const gp_Pnt2d& theP2) const 0247 { 0248 gp_Ax22d aTemp = *this; 0249 aTemp.Translate (theP1, theP2); 0250 return aTemp; 0251 } 0252 0253 //! Dumps the content of me into the stream 0254 Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const; 0255 0256 private: 0257 0258 gp_Pnt2d point; 0259 gp_Dir2d vydir; 0260 gp_Dir2d vxdir; 0261 0262 }; 0263 0264 // ======================================================================= 0265 // function : SetDirection 0266 // purpose : 0267 // ======================================================================= 0268 inline void gp_Ax22d::SetXAxis (const gp_Ax2d& theA1) 0269 { 0270 Standard_Boolean isSign = (vxdir.Crossed(vydir)) >= 0.0; 0271 point = theA1.Location (); 0272 vxdir = theA1.Direction(); 0273 if (isSign) 0274 { 0275 vydir.SetCoord (-vxdir.Y(), vxdir.X()); 0276 } 0277 else 0278 { 0279 vydir.SetCoord (vxdir.Y(), -vxdir.X()); 0280 } 0281 } 0282 0283 // ======================================================================= 0284 // function : SetDirection 0285 // purpose : 0286 // ======================================================================= 0287 inline void gp_Ax22d::SetYAxis (const gp_Ax2d& theA1) 0288 { 0289 Standard_Boolean isSign = (vxdir.Crossed(vydir)) >= 0.0; 0290 point = theA1.Location (); 0291 vydir = theA1.Direction(); 0292 if (isSign) 0293 { 0294 vxdir.SetCoord (vydir.Y(), -vydir.X()); 0295 } 0296 else 0297 { 0298 vxdir.SetCoord (-vydir.Y(), vydir.X()); 0299 } 0300 } 0301 0302 // ======================================================================= 0303 // function : SetXDirection 0304 // purpose : 0305 // ======================================================================= 0306 inline void gp_Ax22d::SetXDirection (const gp_Dir2d& theVx) 0307 { 0308 Standard_Boolean isSign = (vxdir.Crossed(vydir)) >= 0.0; 0309 vxdir = theVx; 0310 if (isSign) 0311 { 0312 vydir.SetCoord (-theVx.Y(), theVx.X()); 0313 } 0314 else 0315 { 0316 vydir.SetCoord (theVx.Y(), -theVx.X()); 0317 } 0318 } 0319 0320 // ======================================================================= 0321 // function : SetYDirection 0322 // purpose : 0323 // ======================================================================= 0324 inline void gp_Ax22d::SetYDirection (const gp_Dir2d& theVy) 0325 { 0326 Standard_Boolean isSign = (vxdir.Crossed(vydir)) >= 0.0; 0327 vydir = theVy; 0328 if (isSign) 0329 { 0330 vxdir.SetCoord (theVy.Y(), -theVy.X()); 0331 } 0332 else 0333 { 0334 vxdir.SetCoord (-theVy.Y(), theVy.X()); 0335 } 0336 } 0337 0338 // ======================================================================= 0339 // function : Rotate 0340 // purpose : 0341 // ======================================================================= 0342 inline void gp_Ax22d::Rotate (const gp_Pnt2d& theP, const Standard_Real theAng) 0343 { 0344 gp_Pnt2d aTemp = point; 0345 aTemp.Rotate (theP, theAng); 0346 point = aTemp; 0347 vxdir.Rotate (theAng); 0348 vydir.Rotate (theAng); 0349 } 0350 0351 // ======================================================================= 0352 // function : Scale 0353 // purpose : 0354 // ======================================================================= 0355 inline void gp_Ax22d::Scale (const gp_Pnt2d& theP, const Standard_Real theS) 0356 { 0357 gp_Pnt2d aTemp = point; 0358 aTemp.Scale (theP, theS); 0359 point = aTemp; 0360 if (theS < 0.0) 0361 { 0362 vxdir.Reverse(); 0363 vydir.Reverse(); 0364 } 0365 } 0366 0367 // ======================================================================= 0368 // function : Transform 0369 // purpose : 0370 // ======================================================================= 0371 inline void gp_Ax22d::Transform (const gp_Trsf2d& theT) 0372 { 0373 gp_Pnt2d aTemp = point; 0374 aTemp.Transform (theT); 0375 point = aTemp; 0376 vxdir.Transform (theT); 0377 vydir.Transform (theT); 0378 } 0379 0380 #endif // _gp_Ax22d_HeaderFile
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |