|
||||
File indexing completed on 2025-01-18 10:03:45
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_Parab_HeaderFile 0016 #define _gp_Parab_HeaderFile 0017 0018 #include <gp_Ax1.hxx> 0019 #include <gp_Lin.hxx> 0020 #include <gp_Pnt.hxx> 0021 #include <Standard_ConstructionError.hxx> 0022 0023 //! Describes a parabola in 3D space. 0024 //! A parabola is defined by its focal length (that is, the 0025 //! distance between its focus and apex) and positioned in 0026 //! space with a coordinate system (a gp_Ax2 object) 0027 //! where: 0028 //! - the origin of the coordinate system is on the apex of 0029 //! the parabola, 0030 //! - the "X Axis" of the coordinate system is the axis of 0031 //! symmetry; the parabola is on the positive side of this axis, and 0032 //! - the origin, "X Direction" and "Y Direction" of the 0033 //! coordinate system define the plane of the parabola. 0034 //! The equation of the parabola in this coordinate system, 0035 //! which is the "local coordinate system" of the parabola, is: 0036 //! @code 0037 //! Y**2 = (2*P) * X. 0038 //! @endcode 0039 //! where P, referred to as the parameter of the parabola, is 0040 //! the distance between the focus and the directrix (P is 0041 //! twice the focal length). 0042 //! The "main Direction" of the local coordinate system gives 0043 //! the normal vector to the plane of the parabola. 0044 //! See Also 0045 //! gce_MakeParab which provides functions for more 0046 //! complex parabola constructions 0047 //! Geom_Parabola which provides additional functions for 0048 //! constructing parabolas and works, in particular, with the 0049 //! parametric equations of parabolas 0050 class gp_Parab 0051 { 0052 public: 0053 0054 DEFINE_STANDARD_ALLOC 0055 0056 //! Creates an indefinite Parabola. 0057 gp_Parab() 0058 : focalLength (RealLast()) 0059 {} 0060 0061 //! Creates a parabola with its local coordinate system "theA2" 0062 //! and it's focal length "Focal". 0063 //! The XDirection of theA2 defines the axis of symmetry of the 0064 //! parabola. The YDirection of theA2 is parallel to the directrix 0065 //! of the parabola. The Location point of theA2 is the vertex of 0066 //! the parabola 0067 //! Raises ConstructionError if theFocal < 0.0 0068 //! Raised if theFocal < 0.0 0069 gp_Parab (const gp_Ax2& theA2, const Standard_Real theFocal) 0070 : pos (theA2), 0071 focalLength (theFocal) 0072 { 0073 Standard_ConstructionError_Raise_if (theFocal < 0.0, "gp_Parab() - focal length should be >= 0"); 0074 } 0075 0076 //! theD is the directrix of the parabola and theF the focus point. 0077 //! The symmetry axis (XAxis) of the parabola is normal to the 0078 //! directrix and pass through the focus point theF, but its 0079 //! location point is the vertex of the parabola. 0080 //! The YAxis of the parabola is parallel to theD and its location 0081 //! point is the vertex of the parabola. The normal to the plane 0082 //! of the parabola is the cross product between the XAxis and the 0083 //! YAxis. 0084 gp_Parab (const gp_Ax1& theD, const gp_Pnt& theF); 0085 0086 //! Modifies this parabola by redefining its local coordinate system so that 0087 //! - its origin and "main Direction" become those of the 0088 //! axis theA1 (the "X Direction" and "Y Direction" are then 0089 //! recomputed in the same way as for any gp_Ax2) 0090 //! Raises ConstructionError if the direction of theA1 is parallel to the previous 0091 //! XAxis of the parabola. 0092 void SetAxis (const gp_Ax1& theA1) { pos.SetAxis (theA1); } 0093 0094 //! Changes the focal distance of the parabola. 0095 //! Raises ConstructionError if theFocal < 0.0 0096 void SetFocal (const Standard_Real theFocal) 0097 { 0098 Standard_ConstructionError_Raise_if (theFocal < 0.0, "gp_Parab::SetFocal() - focal length should be >= 0"); 0099 focalLength = theFocal; 0100 } 0101 0102 //! Changes the location of the parabola. It is the vertex of 0103 //! the parabola. 0104 void SetLocation (const gp_Pnt& theP) { pos.SetLocation (theP); } 0105 0106 //! Changes the local coordinate system of the parabola. 0107 void SetPosition (const gp_Ax2& theA2) { pos = theA2; } 0108 0109 //! Returns the main axis of the parabola. 0110 //! It is the axis normal to the plane of the parabola passing 0111 //! through the vertex of the parabola. 0112 const gp_Ax1& Axis() const { return pos.Axis(); } 0113 0114 //! Computes the directrix of this parabola. 0115 //! The directrix is: 0116 //! - a line parallel to the "Y Direction" of the local 0117 //! coordinate system of this parabola, and 0118 //! - located on the negative side of the axis of symmetry, 0119 //! at a distance from the apex which is equal to the focal 0120 //! length of this parabola. 0121 //! The directrix is returned as an axis (a gp_Ax1 object), 0122 //! the origin of which is situated on the "X Axis" of this parabola. 0123 gp_Ax1 Directrix() const; 0124 0125 //! Returns the distance between the vertex and the focus 0126 //! of the parabola. 0127 Standard_Real Focal() const { return focalLength; } 0128 0129 //! - Computes the focus of the parabola. 0130 gp_Pnt Focus() const; 0131 0132 //! Returns the vertex of the parabola. It is the "Location" 0133 //! point of the coordinate system of the parabola. 0134 const gp_Pnt& Location() const { return pos.Location(); } 0135 0136 //! Computes the parameter of the parabola. 0137 //! It is the distance between the focus and the directrix of 0138 //! the parabola. This distance is twice the focal length. 0139 Standard_Real Parameter() const { return 2.0 * focalLength; } 0140 0141 //! Returns the local coordinate system of the parabola. 0142 const gp_Ax2& Position() const { return pos; } 0143 0144 //! Returns the symmetry axis of the parabola. The location point 0145 //! of the axis is the vertex of the parabola. 0146 gp_Ax1 XAxis() const { return gp_Ax1 (pos.Location(), pos.XDirection()); } 0147 0148 //! It is an axis parallel to the directrix of the parabola. 0149 //! The location point of this axis is the vertex of the parabola. 0150 gp_Ax1 YAxis() const { return gp_Ax1 (pos.Location(), pos.YDirection()); } 0151 0152 Standard_EXPORT void Mirror (const gp_Pnt& theP); 0153 0154 //! Performs the symmetrical transformation of a parabola 0155 //! with respect to the point theP which is the center of the 0156 //! symmetry. 0157 Standard_NODISCARD Standard_EXPORT gp_Parab Mirrored (const gp_Pnt& theP) const; 0158 0159 Standard_EXPORT void Mirror (const gp_Ax1& theA1); 0160 0161 //! Performs the symmetrical transformation of a parabola 0162 //! with respect to an axis placement which is the axis of 0163 //! the symmetry. 0164 Standard_NODISCARD Standard_EXPORT gp_Parab Mirrored (const gp_Ax1& theA1) const; 0165 0166 Standard_EXPORT void Mirror (const gp_Ax2& theA2); 0167 0168 //! Performs the symmetrical transformation of a parabola 0169 //! with respect to a plane. The axis placement theA2 locates 0170 //! the plane of the symmetry (Location, XDirection, YDirection). 0171 Standard_NODISCARD Standard_EXPORT gp_Parab Mirrored (const gp_Ax2& theA2) const; 0172 0173 void Rotate (const gp_Ax1& theA1, const Standard_Real theAng) { pos.Rotate (theA1, theAng); } 0174 0175 //! Rotates a parabola. theA1 is the axis of the rotation. 0176 //! Ang is the angular value of the rotation in radians. 0177 Standard_NODISCARD gp_Parab Rotated (const gp_Ax1& theA1, const Standard_Real theAng) const 0178 { 0179 gp_Parab aPrb = *this; 0180 aPrb.pos.Rotate (theA1, theAng); 0181 return aPrb; 0182 } 0183 0184 void Scale (const gp_Pnt& theP, const Standard_Real theS); 0185 0186 //! Scales a parabola. theS is the scaling value. 0187 //! If theS is negative the direction of the symmetry axis 0188 //! XAxis is reversed and the direction of the YAxis too. 0189 Standard_NODISCARD gp_Parab Scaled (const gp_Pnt& theP, const Standard_Real theS) const; 0190 0191 void Transform (const gp_Trsf& theT); 0192 0193 //! Transforms a parabola with the transformation theT from class Trsf. 0194 Standard_NODISCARD gp_Parab Transformed (const gp_Trsf& theT) const; 0195 0196 void Translate (const gp_Vec& theV) { pos.Translate (theV); } 0197 0198 //! Translates a parabola in the direction of the vector theV. 0199 //! The magnitude of the translation is the vector's magnitude. 0200 Standard_NODISCARD gp_Parab Translated (const gp_Vec& theV) const 0201 { 0202 gp_Parab aPrb = *this; 0203 aPrb.pos.Translate (theV); 0204 return aPrb; 0205 } 0206 0207 void Translate (const gp_Pnt& theP1, const gp_Pnt& theP2) { pos.Translate (theP1, theP2); } 0208 0209 //! Translates a parabola from the point theP1 to the point theP2. 0210 Standard_NODISCARD gp_Parab Translated (const gp_Pnt& theP1, const gp_Pnt& theP2) const 0211 { 0212 gp_Parab aPrb = *this; 0213 aPrb.pos.Translate (theP1, theP2); 0214 return aPrb; 0215 } 0216 0217 private: 0218 0219 gp_Ax2 pos; 0220 Standard_Real focalLength; 0221 0222 }; 0223 0224 //======================================================================= 0225 //function : gp_Parab 0226 // purpose : 0227 //======================================================================= 0228 inline gp_Parab::gp_Parab (const gp_Ax1& theD, 0229 const gp_Pnt& theF) 0230 { 0231 gp_Lin aDroite (theD); 0232 focalLength = aDroite.Distance (theF) / 2.; 0233 gp_Ax1 anAx = aDroite.Normal (theF).Position(); 0234 gp_Ax1 anAy = aDroite.Position(); 0235 const gp_Dir& aDD = anAx.Direction(); 0236 pos = gp_Ax2 (gp_Pnt (theF.X() - focalLength * aDD.X(), 0237 theF.Y() - focalLength * aDD.Y(), 0238 theF.Z() - focalLength * aDD.Z()), 0239 anAx.Direction().Crossed (anAy.Direction()), 0240 anAx.Direction()); 0241 } 0242 0243 //======================================================================= 0244 //function : Directrix 0245 // purpose : 0246 //======================================================================= 0247 inline gp_Ax1 gp_Parab::Directrix() const 0248 { 0249 const gp_Pnt& aPP = pos.Location (); 0250 const gp_Dir& aDD = pos.XDirection(); 0251 gp_Pnt aP (aPP.X() - focalLength * aDD.X(), 0252 aPP.Y() - focalLength * aDD.Y(), 0253 aPP.Z() - focalLength * aDD.Z()); 0254 return gp_Ax1 (aP, pos.YDirection()); 0255 } 0256 0257 //======================================================================= 0258 //function : Focus 0259 // purpose : 0260 //======================================================================= 0261 inline gp_Pnt gp_Parab::Focus() const 0262 { 0263 const gp_Pnt& aPP = pos.Location (); 0264 const gp_Dir& aDD = pos.XDirection(); 0265 return gp_Pnt (aPP.X() + focalLength * aDD.X(), 0266 aPP.Y() + focalLength * aDD.Y(), 0267 aPP.Z() + focalLength * aDD.Z()); 0268 } 0269 0270 //======================================================================= 0271 //function : Scale 0272 // purpose : 0273 //======================================================================= 0274 inline void gp_Parab::Scale (const gp_Pnt& theP, const Standard_Real theS) 0275 { 0276 focalLength *= theS; 0277 if (focalLength < 0) 0278 { 0279 focalLength = -focalLength; 0280 } 0281 pos.Scale (theP, theS); 0282 } 0283 0284 //======================================================================= 0285 //function : Scaled 0286 // purpose : 0287 //======================================================================= 0288 inline gp_Parab gp_Parab::Scaled (const gp_Pnt& theP, const Standard_Real theS) const 0289 { 0290 gp_Parab aPrb = *this; 0291 aPrb.focalLength *= theS; 0292 if (aPrb.focalLength < 0) 0293 { 0294 aPrb.focalLength = -aPrb.focalLength; 0295 } 0296 aPrb.pos.Scale (theP, theS); 0297 return aPrb; 0298 } 0299 0300 //======================================================================= 0301 //function : Transform 0302 // purpose : 0303 //======================================================================= 0304 inline void gp_Parab::Transform (const gp_Trsf& theT) 0305 { 0306 focalLength *= theT.ScaleFactor(); 0307 if (focalLength < 0) 0308 { 0309 focalLength = -focalLength; 0310 } 0311 pos.Transform (theT); 0312 } 0313 0314 //======================================================================= 0315 //function : Transformed 0316 // purpose : 0317 //======================================================================= 0318 inline gp_Parab gp_Parab::Transformed (const gp_Trsf& theT) const 0319 { 0320 gp_Parab aPrb = *this; 0321 aPrb.focalLength *= theT.ScaleFactor(); 0322 if (aPrb.focalLength < 0) 0323 { 0324 aPrb.focalLength = -aPrb.focalLength; 0325 } 0326 aPrb.pos.Transform (theT); 0327 return aPrb; 0328 } 0329 0330 #endif // _gp_Parab_HeaderFile
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |