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_Parab2d_HeaderFile
16 #define _gp_Parab2d_HeaderFile
18 #include <gp_Ax22d.hxx>
19 #include <gp_Ax2d.hxx>
20 #include <gp_Pnt2d.hxx>
21 #include <Standard_ConstructionError.hxx>
23 //! Describes a parabola in the plane (2D space).
24 //! A parabola is defined by its focal length (that is, the
25 //! distance between its focus and apex) and positioned in
26 //! the plane with a coordinate system (a gp_Ax22d object) where:
27 //! - the origin of the coordinate system is on the apex of
29 //! - the "X Axis" of the coordinate system is the axis of
30 //! symmetry; the parabola is on the positive side of this axis.
31 //! This coordinate system is the "local coordinate system"
32 //! of the parabola. Its orientation (direct or indirect sense)
33 //! gives an implicit orientation to the parabola.
34 //! In this coordinate system, the equation for the parabola is:
38 //! where P, referred to as the parameter of the parabola, is
39 //! the distance between the focus and the directrix (P is
40 //! twice the focal length).
42 //! GCE2d_MakeParab2d which provides functions for
43 //! more complex parabola constructions
44 //! Geom2d_Parabola which provides additional functions
45 //! for constructing parabolas and works, in particular, with
46 //! the parametric equations of parabolas
53 //! Creates an indefinite parabola.
55 : focalLength (RealLast())
58 //! Creates a parabola with its vertex point, its axis of symmetry
59 //! ("XAxis") and its focal length.
60 //! The sense of parametrization is given by theSense. If theSense == TRUE
61 //! (by default) then right-handed coordinate system is used,
62 //! otherwise - left-handed.
63 //! Warnings : It is possible to have FocalLength = 0. In this case,
64 //! the parabola looks like a line, which is parallel to the symmetry-axis.
65 //! Raises ConstructionError if FocalLength < 0.0
66 gp_Parab2d (const gp_Ax2d& theMirrorAxis,
67 const Standard_Real theFocalLength,
68 const Standard_Boolean theSense = Standard_True)
69 : focalLength (theFocalLength)
71 pos = gp_Ax22d (theMirrorAxis, theSense);
72 Standard_ConstructionError_Raise_if (theFocalLength < 0.0, "gp_Parab2d() - focal length should be >= 0");
75 //! Creates a parabola with its vertex point, its axis of symmetry
76 //! ("XAxis"), correspond Y-axis and its focal length.
77 //! Warnings : It is possible to have FocalLength = 0. In this case,
78 //! the parabola looks like a line, which is parallel to the symmetry-axis.
79 //! Raises ConstructionError if Focal < 0.0
80 gp_Parab2d (const gp_Ax22d& theAxes, const Standard_Real theFocalLength)
82 focalLength (theFocalLength)
84 Standard_ConstructionError_Raise_if (theFocalLength < 0.0, "gp_Parab2d() - focal length should be >= 0");
87 //! Creates a parabola with the directrix and the focus point.
88 //! Y-axis of the parabola (in User Coordinate System - UCS) is
89 //! the direction of theDirectrix. X-axis always directs from theDirectrix
90 //! to theFocus point and always comes through theFocus.
91 //! Apex of the parabola is a middle point between the theFocus and the
92 //! intersection point of theDirectrix and the X-axis.
93 //! Warnings : It is possible to have FocalLength = 0 (when theFocus lies
94 //! in theDirectrix). In this case, X-direction of the parabola is defined
95 //! by theSense parameter. If theSense == TRUE (by default) then right-handed
96 //! coordinate system is used, otherwise - left-handed. Result parabola will look
97 //! like a line, which is perpendicular to the directrix.
98 Standard_EXPORT gp_Parab2d (const gp_Ax2d& theDirectrix,
99 const gp_Pnt2d& theFocus,
100 const Standard_Boolean theSense = Standard_True);
102 //! Changes the focal distance of the parabola
103 //! Warnings : It is possible to have theFocal = 0.
104 //! Raises ConstructionError if theFocal < 0.0
105 void SetFocal (const Standard_Real theFocal)
107 Standard_ConstructionError_Raise_if (theFocal < 0.0, "gp_Parab2d::SetFocal() - focal length should be >= 0");
108 focalLength = theFocal;
111 //! Changes the "Location" point of the parabola. It is the
112 //! vertex of the parabola.
113 void SetLocation (const gp_Pnt2d& theP) { pos.SetLocation (theP); }
115 //! Modifies this parabola, by redefining its local coordinate system so that
116 //! its origin and "X Direction" become those of the axis
117 //! MA. The "Y Direction" of the local coordinate system is
118 //! then recomputed. The orientation of the local
119 //! coordinate system is not modified.
120 void SetMirrorAxis (const gp_Ax2d& theA) { pos.SetXAxis (theA); }
122 //! Changes the local coordinate system of the parabola.
123 //! The "Location" point of A becomes the vertex of the parabola.
124 void SetAxis (const gp_Ax22d& theA) { pos.SetAxis (theA); }
126 //! Computes the coefficients of the implicit equation of the parabola
127 //! (in WCS - World Coordinate System).
129 //! theA * (X**2) + theB * (Y**2) + 2*theC*(X*Y) + 2*theD*X + 2*theE*Y + theF = 0.
131 Standard_EXPORT void Coefficients (Standard_Real& theA, Standard_Real& theB,
132 Standard_Real& theC, Standard_Real& theD,
133 Standard_Real& theE, Standard_Real& theF) const;
135 //! Computes the directrix of the parabola.
136 //! The directrix is:
137 //! - a line parallel to the "Y Direction" of the local
138 //! coordinate system of this parabola, and
139 //! - located on the negative side of the axis of symmetry,
140 //! at a distance from the apex which is equal to the focal length of this parabola.
141 //! The directrix is returned as an axis (a gp_Ax2d object),
142 //! the origin of which is situated on the "X Axis" of this parabola.
143 gp_Ax2d Directrix() const;
145 //! Returns the distance between the vertex and the focus
147 Standard_Real Focal() const { return focalLength; }
149 //! Returns the focus of the parabola.
150 gp_Pnt2d Focus() const
152 return gp_Pnt2d (pos.Location().X() + focalLength * pos.XDirection().X(),
153 pos.Location().Y() + focalLength * pos.XDirection().Y());
156 //! Returns the vertex of the parabola.
157 gp_Pnt2d Location() const { return pos.Location(); }
159 //! Returns the symmetry axis of the parabola.
160 //! The "Location" point of this axis is the vertex of the parabola.
161 gp_Ax2d MirrorAxis() const { return pos.XAxis(); }
163 //! Returns the local coordinate system of the parabola.
164 //! The "Location" point of this axis is the vertex of the parabola.
165 gp_Ax22d Axis() const { return pos; }
167 //! Returns the distance between the focus and the
168 //! directrix of the parabola.
169 Standard_Real Parameter() const { return 2.0 * focalLength; }
173 gp_Dir2d aTemp = pos.YDirection();
175 pos.SetAxis (gp_Ax22d (pos.Location(), pos.XDirection(), aTemp));
178 //! Reverses the orientation of the local coordinate system
179 //! of this parabola (the "Y Direction" is reversed).
180 //! Therefore, the implicit orientation of this parabola is reversed.
182 //! - Reverse assigns the result to this parabola, while
183 //! - Reversed creates a new one.
184 Standard_NODISCARD gp_Parab2d Reversed() const;
186 //! Returns true if the local coordinate system is direct
187 //! and false in the other case.
188 Standard_Boolean IsDirect() const
190 return (pos.XDirection().Crossed (pos.YDirection())) >= 0.0;
193 Standard_EXPORT void Mirror (const gp_Pnt2d& theP);
195 //! Performs the symmetrical transformation of a parabola with respect
196 //! to the point theP which is the center of the symmetry
197 Standard_NODISCARD Standard_EXPORT gp_Parab2d Mirrored (const gp_Pnt2d& theP) const;
199 Standard_EXPORT void Mirror (const gp_Ax2d& theA);
201 //! Performs the symmetrical transformation of a parabola with respect
202 //! to an axis placement which is the axis of the symmetry.
203 Standard_NODISCARD Standard_EXPORT gp_Parab2d Mirrored (const gp_Ax2d& theA) const;
205 void Rotate (const gp_Pnt2d& theP, const Standard_Real theAng) { pos.Rotate (theP, theAng); }
207 //! Rotates a parabola. theP is the center of the rotation.
208 //! theAng is the angular value of the rotation in radians.
209 Standard_NODISCARD gp_Parab2d Rotated (const gp_Pnt2d& theP, const Standard_Real theAng) const
211 gp_Parab2d aPrb = *this;
212 aPrb.pos.Rotate (theP, theAng);
216 void Scale (const gp_Pnt2d& theP, const Standard_Real theS);
218 //! Scales a parabola. theS is the scaling value.
219 //! If theS is negative the direction of the symmetry axis
220 //! "XAxis" is reversed and the direction of the "YAxis" too.
221 Standard_NODISCARD gp_Parab2d Scaled (const gp_Pnt2d& theP, const Standard_Real theS) const;
223 void Transform (const gp_Trsf2d& theT);
225 //! Transforms an parabola with the transformation theT from class Trsf2d.
226 Standard_NODISCARD gp_Parab2d Transformed (const gp_Trsf2d& theT) const;
228 void Translate (const gp_Vec2d& theV) { pos.Translate (theV); }
230 //! Translates a parabola in the direction of the vectorthe theV.
231 //! The magnitude of the translation is the vector's magnitude.
232 Standard_NODISCARD gp_Parab2d Translated (const gp_Vec2d& theV) const
234 gp_Parab2d aPrb = *this;
235 aPrb.pos.Translate (theV);
239 void Translate (const gp_Pnt2d& theP1, const gp_Pnt2d& theP2) { pos.Translate (theP1, theP2); }
241 //! Translates a parabola from the point theP1 to the point theP2.
242 Standard_NODISCARD gp_Parab2d Translated (const gp_Pnt2d& theP1, const gp_Pnt2d& theP2) const
244 gp_Parab2d aPrb = *this;
245 aPrb.pos.Translate (theP1, theP2);
252 Standard_Real focalLength;
256 //=======================================================================
257 //function : Directrix
259 //=======================================================================
260 inline gp_Ax2d gp_Parab2d::Directrix() const
262 gp_Pnt2d aP (pos.Location().X() - focalLength * pos.XDirection().X(),
263 pos.Location().Y() - focalLength * pos.XDirection().Y());
264 gp_Dir2d aV (pos.YDirection());
265 return gp_Ax2d (aP, aV);
268 //=======================================================================
269 //function : Reversed
271 //=======================================================================
272 inline gp_Parab2d gp_Parab2d::Reversed() const
274 gp_Parab2d aP = *this;
275 gp_Dir2d aTemp = pos.YDirection();
277 aP.pos.SetAxis (gp_Ax22d (pos.Location(), pos.XDirection(), aTemp));
281 //=======================================================================
284 //=======================================================================
285 inline void gp_Parab2d::Scale (const gp_Pnt2d& theP, const Standard_Real theS)
290 focalLength = -focalLength;
292 pos.Scale (theP, theS);
295 //=======================================================================
298 //=======================================================================
299 inline gp_Parab2d gp_Parab2d::Scaled (const gp_Pnt2d& theP, const Standard_Real theS) const
301 gp_Parab2d aPrb = *this;
302 aPrb.focalLength *= theS;
303 if (aPrb.focalLength < 0)
305 aPrb.focalLength = -aPrb.focalLength;
307 aPrb.pos.Scale (theP, theS);
311 //=======================================================================
312 //function : Transform
314 //=======================================================================
315 inline void gp_Parab2d::Transform (const gp_Trsf2d& theT)
317 focalLength *= theT.ScaleFactor();
320 focalLength = -focalLength;
322 pos.Transform (theT);
325 //=======================================================================
326 //function : Transformed
328 //=======================================================================
329 inline gp_Parab2d gp_Parab2d::Transformed (const gp_Trsf2d& theT) const
331 gp_Parab2d aPrb = *this;
332 aPrb.focalLength *= theT.ScaleFactor();
333 if (aPrb.focalLength < 0)
335 aPrb.focalLength = -aPrb.focalLength;
337 aPrb.pos.Transform (theT);
341 #endif // _gp_Parab2d_HeaderFile