42cf5bc1 |
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_Circ_HeaderFile |
16 | #define _gp_Circ_HeaderFile |
17 | |
42cf5bc1 |
18 | #include <gp_Ax1.hxx> |
d5477f8c |
19 | #include <gp_Ax2.hxx> |
20 | #include <gp_Pnt.hxx> |
21 | #include <gp_Trsf.hxx> |
22 | #include <gp_Vec.hxx> |
23 | #include <Standard_ConstructionError.hxx> |
42cf5bc1 |
24 | |
25 | //! Describes a circle in 3D space. |
26 | //! A circle is defined by its radius and positioned in space |
27 | //! with a coordinate system (a gp_Ax2 object) as follows: |
28 | //! - the origin of the coordinate system is the center of the circle, and |
29 | //! - the origin, "X Direction" and "Y Direction" of the |
30 | //! coordinate system define the plane of the circle. |
31 | //! This positioning coordinate system is the "local |
32 | //! coordinate system" of the circle. Its "main Direction" |
33 | //! gives the normal vector to the plane of the circle. The |
34 | //! "main Axis" of the coordinate system is referred to as |
35 | //! the "Axis" of the circle. |
36 | //! Note: when a gp_Circ circle is converted into a |
37 | //! Geom_Circle circle, some implicit properties of the |
38 | //! circle are used explicitly: |
39 | //! - the "main Direction" of the local coordinate system |
40 | //! gives an implicit orientation to the circle (and defines |
41 | //! its trigonometric sense), |
42 | //! - this orientation corresponds to the direction in |
43 | //! which parameter values increase, |
44 | //! - the starting point for parameterization is that of the |
45 | //! "X Axis" of the local coordinate system (i.e. the "X Axis" of the circle). |
46 | //! See Also |
47 | //! gce_MakeCirc which provides functions for more complex circle constructions |
48 | //! Geom_Circle which provides additional functions for |
49 | //! constructing circles and works, in particular, with the |
50 | //! parametric equations of circles |
51 | class gp_Circ |
52 | { |
53 | public: |
54 | |
55 | DEFINE_STANDARD_ALLOC |
56 | |
42cf5bc1 |
57 | //! Creates an indefinite circle. |
d5477f8c |
58 | gp_Circ() : radius (RealLast()) |
59 | {} |
42cf5bc1 |
60 | |
61 | //! A2 locates the circle and gives its orientation in 3D space. |
62 | //! Warnings : |
d5477f8c |
63 | //! It is not forbidden to create a circle with theRadius = 0.0 Raises ConstructionError if theRadius < 0.0 |
64 | gp_Circ (const gp_Ax2& theA2, const Standard_Real theRadius) |
65 | : pos (theA2), |
66 | radius(theRadius) |
67 | { |
68 | Standard_ConstructionError_Raise_if (theRadius < 0.0, "gp_Circ() - radius should be positive number"); |
69 | } |
42cf5bc1 |
70 | |
71 | //! Changes the main axis of the circle. It is the axis |
72 | //! perpendicular to the plane of the circle. |
d5477f8c |
73 | //! Raises ConstructionError if the direction of theA1 |
42cf5bc1 |
74 | //! is parallel to the "XAxis" of the circle. |
d5477f8c |
75 | void SetAxis (const gp_Ax1& theA1) { pos.SetAxis (theA1); } |
42cf5bc1 |
76 | |
77 | //! Changes the "Location" point (center) of the circle. |
d5477f8c |
78 | void SetLocation (const gp_Pnt& theP) { pos.SetLocation (theP); } |
79 | |
42cf5bc1 |
80 | //! Changes the position of the circle. |
d5477f8c |
81 | void SetPosition (const gp_Ax2& theA2) { pos = theA2; } |
82 | |
42cf5bc1 |
83 | //! Modifies the radius of this circle. |
d5477f8c |
84 | //! Warning. This class does not prevent the creation of a circle where theRadius is null. |
42cf5bc1 |
85 | //! Exceptions |
d5477f8c |
86 | //! Standard_ConstructionError if theRadius is negative. |
87 | void SetRadius (const Standard_Real theRadius) |
88 | { |
89 | Standard_ConstructionError_Raise_if (theRadius < 0.0, "gp_Circ::SetRadius() - radius should be positive number"); |
90 | radius = theRadius; |
91 | } |
92 | |
42cf5bc1 |
93 | //! Computes the area of the circle. |
d5477f8c |
94 | Standard_Real Area() const { return M_PI * radius * radius; } |
42cf5bc1 |
95 | |
96 | //! Returns the main axis of the circle. |
97 | //! It is the axis perpendicular to the plane of the circle, |
98 | //! passing through the "Location" point (center) of the circle. |
d5477f8c |
99 | const gp_Ax1& Axis() const { return pos.Axis(); } |
100 | |
42cf5bc1 |
101 | //! Computes the circumference of the circle. |
d5477f8c |
102 | Standard_Real Length() const { return 2. * M_PI * radius; } |
42cf5bc1 |
103 | |
104 | //! Returns the center of the circle. It is the |
105 | //! "Location" point of the local coordinate system |
106 | //! of the circle |
d5477f8c |
107 | const gp_Pnt& Location() const { return pos.Location(); } |
42cf5bc1 |
108 | |
109 | //! Returns the position of the circle. |
110 | //! It is the local coordinate system of the circle. |
d5477f8c |
111 | const gp_Ax2& Position() const { return pos; } |
112 | |
42cf5bc1 |
113 | //! Returns the radius of this circle. |
d5477f8c |
114 | Standard_Real Radius() const { return radius; } |
42cf5bc1 |
115 | |
116 | //! Returns the "XAxis" of the circle. |
117 | //! This axis is perpendicular to the axis of the conic. |
118 | //! This axis and the "Yaxis" define the plane of the conic. |
d5477f8c |
119 | gp_Ax1 XAxis() const { return gp_Ax1 (pos.Location(), pos.XDirection()); } |
42cf5bc1 |
120 | |
121 | //! Returns the "YAxis" of the circle. |
122 | //! This axis and the "Xaxis" define the plane of the conic. |
123 | //! The "YAxis" is perpendicular to the "Xaxis". |
d5477f8c |
124 | gp_Ax1 YAxis() const { return gp_Ax1 (pos.Location(), pos.YDirection()); } |
42cf5bc1 |
125 | |
d5477f8c |
126 | //! Computes the minimum of distance between the point theP and |
42cf5bc1 |
127 | //! any point on the circumference of the circle. |
d5477f8c |
128 | Standard_Real Distance (const gp_Pnt& theP) const { return sqrt (SquareDistance (theP)); } |
129 | |
130 | //! Computes the square distance between <me> and the point theP. |
131 | Standard_Real SquareDistance (const gp_Pnt& theP) const |
132 | { |
133 | gp_Vec aV (Location(), theP); |
134 | Standard_Real aX = aV.Dot (pos.XDirection()); |
135 | Standard_Real anY = aV.Dot (pos.YDirection()); |
136 | Standard_Real aZ = aV.Dot (pos.Direction()); |
137 | Standard_Real aT = sqrt (aX * aX + anY * anY) - radius; |
138 | return (aT * aT + aZ * aZ); |
139 | } |
140 | |
141 | //! Returns True if the point theP is on the circumference. |
142 | //! The distance between <me> and <theP> must be lower or |
143 | //! equal to theLinearTolerance. |
144 | Standard_Boolean Contains (const gp_Pnt& theP, const Standard_Real theLinearTolerance) const { return Distance (theP) <= theLinearTolerance; } |
145 | |
146 | Standard_EXPORT void Mirror (const gp_Pnt& theP); |
42cf5bc1 |
147 | |
148 | //! Performs the symmetrical transformation of a circle |
d5477f8c |
149 | //! with respect to the point theP which is the center of the |
42cf5bc1 |
150 | //! symmetry. |
d5477f8c |
151 | Standard_NODISCARD Standard_EXPORT gp_Circ Mirrored (const gp_Pnt& theP) const; |
152 | |
153 | Standard_EXPORT void Mirror (const gp_Ax1& theA1); |
42cf5bc1 |
154 | |
155 | //! Performs the symmetrical transformation of a circle with |
156 | //! respect to an axis placement which is the axis of the |
157 | //! symmetry. |
d5477f8c |
158 | Standard_NODISCARD Standard_EXPORT gp_Circ Mirrored (const gp_Ax1& theA1) const; |
159 | |
160 | Standard_EXPORT void Mirror (const gp_Ax2& theA2); |
42cf5bc1 |
161 | |
162 | //! Performs the symmetrical transformation of a circle with respect |
d5477f8c |
163 | //! to a plane. The axis placement theA2 locates the plane of the |
42cf5bc1 |
164 | //! of the symmetry : (Location, XDirection, YDirection). |
d5477f8c |
165 | Standard_NODISCARD Standard_EXPORT gp_Circ Mirrored (const gp_Ax2& theA2) const; |
42cf5bc1 |
166 | |
d5477f8c |
167 | void Rotate (const gp_Ax1& theA1, const Standard_Real theAng) { pos.Rotate (theA1, theAng); } |
42cf5bc1 |
168 | |
d5477f8c |
169 | //! Rotates a circle. theA1 is the axis of the rotation. |
170 | //! theAng is the angular value of the rotation in radians. |
171 | Standard_NODISCARD gp_Circ Rotated (const gp_Ax1& theA1, const Standard_Real theAng) const |
172 | { |
173 | gp_Circ aC = *this; |
174 | aC.pos.Rotate (theA1, theAng); |
175 | return aC; |
176 | } |
42cf5bc1 |
177 | |
d5477f8c |
178 | void Scale (const gp_Pnt& theP, const Standard_Real theS); |
42cf5bc1 |
179 | |
d5477f8c |
180 | //! Scales a circle. theS is the scaling value. |
181 | //! Warnings : |
182 | //! If theS is negative the radius stay positive but |
183 | //! the "XAxis" and the "YAxis" are reversed as for |
184 | //! an ellipse. |
185 | Standard_NODISCARD gp_Circ Scaled (const gp_Pnt& theP, const Standard_Real theS) const; |
42cf5bc1 |
186 | |
d5477f8c |
187 | void Transform (const gp_Trsf& theT); |
42cf5bc1 |
188 | |
d5477f8c |
189 | //! Transforms a circle with the transformation theT from class Trsf. |
190 | Standard_NODISCARD gp_Circ Transformed (const gp_Trsf& theT) const; |
42cf5bc1 |
191 | |
d5477f8c |
192 | void Translate (const gp_Vec& theV) { pos.Translate (theV); } |
42cf5bc1 |
193 | |
d5477f8c |
194 | //! Translates a circle in the direction of the vector theV. |
195 | //! The magnitude of the translation is the vector's magnitude. |
196 | Standard_NODISCARD gp_Circ Translated (const gp_Vec& theV) const |
197 | { |
198 | gp_Circ aC = *this; |
199 | aC.pos.Translate (theV); |
200 | return aC; |
201 | } |
202 | |
203 | void Translate (const gp_Pnt& theP1, const gp_Pnt& theP2) { pos.Translate (theP1, theP2); } |
204 | |
205 | //! Translates a circle from the point theP1 to the point theP2. |
206 | Standard_NODISCARD gp_Circ Translated (const gp_Pnt& theP1, const gp_Pnt& theP2) const |
207 | { |
208 | gp_Circ aC = *this; |
209 | aC.pos.Translate (theP1, theP2); |
210 | return aC; |
211 | } |
42cf5bc1 |
212 | |
213 | private: |
214 | |
42cf5bc1 |
215 | gp_Ax2 pos; |
216 | Standard_Real radius; |
217 | |
42cf5bc1 |
218 | }; |
219 | |
d5477f8c |
220 | // ======================================================================= |
221 | // function : Scale |
222 | // purpose : |
223 | // ======================================================================= |
224 | inline void gp_Circ::Scale (const gp_Pnt& theP, const Standard_Real theS) |
225 | { |
226 | radius *= theS; |
227 | if (radius < 0) |
228 | { |
229 | radius = -radius; |
230 | } |
231 | pos.Scale (theP, theS); |
232 | } |
233 | |
234 | // ======================================================================= |
235 | // function : Scaled |
236 | // purpose : |
237 | // ======================================================================= |
238 | inline gp_Circ gp_Circ::Scaled (const gp_Pnt& theP, const Standard_Real theS) const |
239 | { |
240 | gp_Circ aC = *this; |
241 | aC.radius *= theS; |
242 | if (aC.radius < 0) |
243 | { |
244 | aC.radius = -aC.radius; |
245 | } |
246 | aC.pos.Scale (theP, theS); |
247 | return aC; |
248 | } |
249 | |
250 | // ======================================================================= |
251 | // function : Transform |
252 | // purpose : |
253 | // ======================================================================= |
254 | inline void gp_Circ::Transform (const gp_Trsf& theT) |
255 | { |
256 | radius *= theT.ScaleFactor(); |
257 | if (radius < 0) |
258 | { |
259 | radius = -radius; |
260 | } |
261 | pos.Transform (theT); |
262 | } |
263 | |
264 | // ======================================================================= |
265 | // function : Transformed |
266 | // purpose : |
267 | // ======================================================================= |
268 | inline gp_Circ gp_Circ::Transformed (const gp_Trsf& theT) const |
269 | { |
270 | gp_Circ aC = *this; |
271 | aC.radius *= theT.ScaleFactor(); |
272 | if (aC.radius < 0) |
273 | { |
274 | aC.radius = -aC.radius; |
275 | } |
276 | aC.pos.Transform (theT); |
277 | return aC; |
278 | } |
42cf5bc1 |
279 | |
280 | #endif // _gp_Circ_HeaderFile |