|
|
|||
File indexing completed on 2026-07-24 09:16:34
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 DEFINE_STANDARD_ALLOC 0054 0055 //! Creates an indefinite Parabola. 0056 gp_Parab() 0057 : focalLength(RealLast()) 0058 { 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, 0099 "gp_Parab::SetFocal() - focal length should be >= 0"); 0100 focalLength = theFocal; 0101 } 0102 0103 //! Changes the location of the parabola. It is the vertex of 0104 //! the parabola. 0105 void SetLocation(const gp_Pnt& theP) { pos.SetLocation(theP); } 0106 0107 //! Changes the local coordinate system of the parabola. 0108 void SetPosition(const gp_Ax2& theA2) { pos = theA2; } 0109 0110 //! Returns the main axis of the parabola. 0111 //! It is the axis normal to the plane of the parabola passing 0112 //! through the vertex of the parabola. 0113 const gp_Ax1& Axis() const { return pos.Axis(); } 0114 0115 //! Computes the directrix of this parabola. 0116 //! The directrix is: 0117 //! - a line parallel to the "Y Direction" of the local 0118 //! coordinate system of this parabola, and 0119 //! - located on the negative side of the axis of symmetry, 0120 //! at a distance from the apex which is equal to the focal 0121 //! length of this parabola. 0122 //! The directrix is returned as an axis (a gp_Ax1 object), 0123 //! the origin of which is situated on the "X Axis" of this parabola. 0124 gp_Ax1 Directrix() const; 0125 0126 //! Returns the distance between the vertex and the focus 0127 //! of the parabola. 0128 Standard_Real Focal() const { return focalLength; } 0129 0130 //! - Computes the focus of the parabola. 0131 gp_Pnt Focus() const; 0132 0133 //! Returns the vertex of the parabola. It is the "Location" 0134 //! point of the coordinate system of the parabola. 0135 const gp_Pnt& Location() const { return pos.Location(); } 0136 0137 //! Computes the parameter of the parabola. 0138 //! It is the distance between the focus and the directrix of 0139 //! the parabola. This distance is twice the focal length. 0140 Standard_Real Parameter() const { return 2.0 * focalLength; } 0141 0142 //! Returns the local coordinate system of the parabola. 0143 const gp_Ax2& Position() const { return pos; } 0144 0145 //! Returns the symmetry axis of the parabola. The location point 0146 //! of the axis is the vertex of the parabola. 0147 gp_Ax1 XAxis() const { return gp_Ax1(pos.Location(), pos.XDirection()); } 0148 0149 //! It is an axis parallel to the directrix of the parabola. 0150 //! The location point of this axis is the vertex of the parabola. 0151 gp_Ax1 YAxis() const { return gp_Ax1(pos.Location(), pos.YDirection()); } 0152 0153 Standard_EXPORT void Mirror(const gp_Pnt& theP); 0154 0155 //! Performs the symmetrical transformation of a parabola 0156 //! with respect to the point theP which is the center of the 0157 //! symmetry. 0158 Standard_NODISCARD Standard_EXPORT gp_Parab Mirrored(const gp_Pnt& theP) const; 0159 0160 Standard_EXPORT void Mirror(const gp_Ax1& theA1); 0161 0162 //! Performs the symmetrical transformation of a parabola 0163 //! with respect to an axis placement which is the axis of 0164 //! the symmetry. 0165 Standard_NODISCARD Standard_EXPORT gp_Parab Mirrored(const gp_Ax1& theA1) const; 0166 0167 Standard_EXPORT void Mirror(const gp_Ax2& theA2); 0168 0169 //! Performs the symmetrical transformation of a parabola 0170 //! with respect to a plane. The axis placement theA2 locates 0171 //! the plane of the symmetry (Location, XDirection, YDirection). 0172 Standard_NODISCARD Standard_EXPORT gp_Parab Mirrored(const gp_Ax2& theA2) const; 0173 0174 void Rotate(const gp_Ax1& theA1, const Standard_Real theAng) { pos.Rotate(theA1, theAng); } 0175 0176 //! Rotates a parabola. theA1 is the axis of the rotation. 0177 //! Ang is the angular value of the rotation in radians. 0178 Standard_NODISCARD gp_Parab Rotated(const gp_Ax1& theA1, const Standard_Real theAng) const 0179 { 0180 gp_Parab aPrb = *this; 0181 aPrb.pos.Rotate(theA1, theAng); 0182 return aPrb; 0183 } 0184 0185 void Scale(const gp_Pnt& theP, const Standard_Real theS); 0186 0187 //! Scales a parabola. theS is the scaling value. 0188 //! If theS is negative the direction of the symmetry axis 0189 //! XAxis is reversed and the direction of the YAxis too. 0190 Standard_NODISCARD gp_Parab Scaled(const gp_Pnt& theP, const Standard_Real theS) const; 0191 0192 void Transform(const gp_Trsf& theT); 0193 0194 //! Transforms a parabola with the transformation theT from class Trsf. 0195 Standard_NODISCARD gp_Parab Transformed(const gp_Trsf& theT) const; 0196 0197 void Translate(const gp_Vec& theV) { pos.Translate(theV); } 0198 0199 //! Translates a parabola in the direction of the vector theV. 0200 //! The magnitude of the translation is the vector's magnitude. 0201 Standard_NODISCARD gp_Parab Translated(const gp_Vec& theV) const 0202 { 0203 gp_Parab aPrb = *this; 0204 aPrb.pos.Translate(theV); 0205 return aPrb; 0206 } 0207 0208 void Translate(const gp_Pnt& theP1, const gp_Pnt& theP2) { pos.Translate(theP1, theP2); } 0209 0210 //! Translates a parabola from the point theP1 to the point theP2. 0211 Standard_NODISCARD gp_Parab Translated(const gp_Pnt& theP1, const gp_Pnt& theP2) const 0212 { 0213 gp_Parab aPrb = *this; 0214 aPrb.pos.Translate(theP1, theP2); 0215 return aPrb; 0216 } 0217 0218 private: 0219 gp_Ax2 pos; 0220 Standard_Real focalLength; 0221 }; 0222 0223 //======================================================================= 0224 // function : gp_Parab 0225 // purpose : 0226 //======================================================================= 0227 inline gp_Parab::gp_Parab(const gp_Ax1& theD, const gp_Pnt& theF) 0228 { 0229 gp_Lin aDroite(theD); 0230 focalLength = aDroite.Distance(theF) / 2.; 0231 gp_Ax1 anAx = aDroite.Normal(theF).Position(); 0232 gp_Ax1 anAy = aDroite.Position(); 0233 const gp_Dir& aDD = anAx.Direction(); 0234 pos = gp_Ax2(gp_Pnt(theF.X() - focalLength * aDD.X(), 0235 theF.Y() - focalLength * aDD.Y(), 0236 theF.Z() - focalLength * aDD.Z()), 0237 anAx.Direction().Crossed(anAy.Direction()), 0238 anAx.Direction()); 0239 } 0240 0241 //======================================================================= 0242 // function : Directrix 0243 // purpose : 0244 //======================================================================= 0245 inline gp_Ax1 gp_Parab::Directrix() const 0246 { 0247 const gp_Pnt& aPP = pos.Location(); 0248 const gp_Dir& aDD = pos.XDirection(); 0249 gp_Pnt aP(aPP.X() - focalLength * aDD.X(), 0250 aPP.Y() - focalLength * aDD.Y(), 0251 aPP.Z() - focalLength * aDD.Z()); 0252 return gp_Ax1(aP, pos.YDirection()); 0253 } 0254 0255 //======================================================================= 0256 // function : Focus 0257 // purpose : 0258 //======================================================================= 0259 inline gp_Pnt gp_Parab::Focus() const 0260 { 0261 const gp_Pnt& aPP = pos.Location(); 0262 const gp_Dir& aDD = pos.XDirection(); 0263 return gp_Pnt(aPP.X() + focalLength * aDD.X(), 0264 aPP.Y() + focalLength * aDD.Y(), 0265 aPP.Z() + focalLength * aDD.Z()); 0266 } 0267 0268 //======================================================================= 0269 // function : Scale 0270 // purpose : 0271 //======================================================================= 0272 inline void gp_Parab::Scale(const gp_Pnt& theP, const Standard_Real theS) 0273 { 0274 focalLength *= theS; 0275 if (focalLength < 0) 0276 { 0277 focalLength = -focalLength; 0278 } 0279 pos.Scale(theP, theS); 0280 } 0281 0282 //======================================================================= 0283 // function : Scaled 0284 // purpose : 0285 //======================================================================= 0286 inline gp_Parab gp_Parab::Scaled(const gp_Pnt& theP, const Standard_Real theS) const 0287 { 0288 gp_Parab aPrb = *this; 0289 aPrb.focalLength *= theS; 0290 if (aPrb.focalLength < 0) 0291 { 0292 aPrb.focalLength = -aPrb.focalLength; 0293 } 0294 aPrb.pos.Scale(theP, theS); 0295 return aPrb; 0296 } 0297 0298 //======================================================================= 0299 // function : Transform 0300 // purpose : 0301 //======================================================================= 0302 inline void gp_Parab::Transform(const gp_Trsf& theT) 0303 { 0304 focalLength *= theT.ScaleFactor(); 0305 if (focalLength < 0) 0306 { 0307 focalLength = -focalLength; 0308 } 0309 pos.Transform(theT); 0310 } 0311 0312 //======================================================================= 0313 // function : Transformed 0314 // purpose : 0315 //======================================================================= 0316 inline gp_Parab gp_Parab::Transformed(const gp_Trsf& theT) const 0317 { 0318 gp_Parab aPrb = *this; 0319 aPrb.focalLength *= theT.ScaleFactor(); 0320 if (aPrb.focalLength < 0) 0321 { 0322 aPrb.focalLength = -aPrb.focalLength; 0323 } 0324 aPrb.pos.Transform(theT); 0325 return aPrb; 0326 } 0327 0328 #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 |
|