b311480e |
1 | // Copyright (c) 1995-1999 Matra Datavision |
2 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
3 | // |
4 | // The content of this file is subject to the Open CASCADE Technology Public |
5 | // License Version 6.5 (the "License"). You may not use the content of this file |
6 | // except in compliance with the License. Please obtain a copy of the License |
7 | // at http://www.opencascade.org and read it completely before using this file. |
8 | // |
9 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
10 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
11 | // |
12 | // The Original Code and all software distributed under the License is |
13 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
14 | // Initial Developer hereby disclaims all such warranties, including without |
15 | // limitation, any warranties of merchantability, fitness for a particular |
16 | // purpose or non-infringement. Please see the License for the specific terms |
17 | // and conditions governing the rights and limitations under the License. |
18 | |
7fd59977 |
19 | |
20 | // Modified by skv - Fri Apr 8 10:28:10 2005 OCC8559 |
21 | |
22 | |
23 | #include <gp.hxx> |
24 | #include <Standard_ConstructionError.hxx> |
25 | |
26 | inline gp_Elips::gp_Elips () : |
27 | majorRadius (RealLast()), |
28 | minorRadius (RealSmall()) |
29 | { } |
30 | |
31 | inline gp_Elips::gp_Elips (const gp_Ax2& A2, |
32 | const Standard_Real MajorRadius, |
33 | const Standard_Real MinorRadius) : |
34 | pos(A2), |
35 | majorRadius (MajorRadius), |
36 | minorRadius (MinorRadius) |
37 | { |
38 | Standard_ConstructionError_Raise_if |
39 | (MinorRadius < 0.0 || MajorRadius < MinorRadius,""); |
40 | } |
41 | |
42 | inline Standard_Real gp_Elips::Area() const |
c6541a0c |
43 | { return M_PI * majorRadius * minorRadius; } |
7fd59977 |
44 | |
45 | inline Standard_Real gp_Elips::MajorRadius() const |
46 | { return majorRadius; } |
47 | |
48 | inline Standard_Real gp_Elips::MinorRadius() const |
49 | { return minorRadius; } |
50 | |
51 | inline Standard_Real gp_Elips::Parameter() const |
52 | { |
53 | if (majorRadius == 0.0) return 0.0; |
54 | else return (minorRadius * minorRadius) / majorRadius; |
55 | } |
56 | |
57 | inline const gp_Ax2& gp_Elips::Position() const |
58 | { return pos; } |
59 | |
60 | inline const gp_Ax1& gp_Elips::Axis () const |
61 | { return pos.Axis(); } |
62 | |
63 | inline gp_Ax1 gp_Elips::Directrix1() const |
64 | { |
65 | Standard_Real E = Eccentricity(); |
66 | Standard_ConstructionError_Raise_if (E <= gp::Resolution(), ""); |
67 | gp_XYZ Orig = pos.XDirection().XYZ(); |
68 | Orig.Multiply (majorRadius/E); |
69 | Orig.Add (pos.Location().XYZ()); |
70 | return gp_Ax1 (gp_Pnt(Orig), pos.YDirection()); |
71 | } |
72 | |
73 | inline gp_Ax1 gp_Elips::Directrix2() const |
74 | { |
75 | Standard_Real E = Eccentricity(); |
76 | Standard_ConstructionError_Raise_if (E <= gp::Resolution(), ""); |
77 | gp_XYZ Orig = pos.XDirection().XYZ(); |
78 | Orig.Multiply (-majorRadius/E); |
79 | Orig.Add (pos.Location().XYZ()); |
80 | return gp_Ax1 (gp_Pnt(Orig), pos.YDirection()); |
81 | } |
82 | |
83 | inline Standard_Real gp_Elips::Eccentricity() const |
84 | { |
85 | if (majorRadius == 0.0) { return 0.0; } |
86 | else { |
87 | return sqrt(majorRadius * majorRadius - |
88 | minorRadius * minorRadius) / majorRadius; |
89 | } |
90 | } |
91 | |
92 | inline Standard_Real gp_Elips::Focal() const |
93 | { |
94 | return 2.0 * sqrt(majorRadius * majorRadius - |
95 | minorRadius * minorRadius); |
96 | } |
97 | |
98 | inline gp_Pnt gp_Elips::Focus1() const |
99 | { |
100 | Standard_Real C = sqrt(majorRadius * majorRadius - |
101 | minorRadius * minorRadius); |
102 | const gp_Pnt& PP = pos.Location (); |
103 | const gp_Dir& DD = pos.XDirection(); |
104 | return gp_Pnt (PP.X() + C * DD.X(), |
105 | PP.Y() + C * DD.Y(), |
106 | PP.Z() + C * DD.Z()); |
107 | } |
108 | |
109 | inline gp_Pnt gp_Elips::Focus2() const |
110 | { |
111 | Standard_Real C = sqrt(majorRadius * majorRadius - |
112 | minorRadius * minorRadius); |
113 | const gp_Pnt& PP = pos.Location (); |
114 | const gp_Dir& DD = pos.XDirection(); |
115 | return gp_Pnt (PP.X() - C * DD.X(), |
116 | PP.Y() - C * DD.Y(), |
117 | PP.Z() - C * DD.Z()); |
118 | } |
119 | |
120 | inline const gp_Pnt& gp_Elips::Location () const |
121 | { return pos.Location(); } |
122 | |
123 | inline gp_Ax1 gp_Elips::XAxis () const |
124 | { return gp_Ax1 (pos.Location(), pos.XDirection()); } |
125 | |
126 | inline gp_Ax1 gp_Elips::YAxis () const |
127 | { return gp_Ax1 (pos.Location(), pos.YDirection()); } |
128 | |
129 | inline void gp_Elips::SetAxis (const gp_Ax1& A1) |
130 | { pos.SetAxis(A1); } |
131 | |
132 | inline void gp_Elips::SetPosition (const gp_Ax2& A2) |
133 | { pos = A2; } |
134 | |
135 | inline void gp_Elips::SetLocation (const gp_Pnt& P) |
136 | { pos.SetLocation (P); } |
137 | |
138 | inline void gp_Elips::SetMajorRadius (const Standard_Real R) |
139 | { |
140 | Standard_ConstructionError_Raise_if(R < minorRadius,""); |
141 | majorRadius = R; |
142 | } |
143 | |
144 | inline void gp_Elips::SetMinorRadius (const Standard_Real R) |
145 | { |
146 | Standard_ConstructionError_Raise_if(R < 0.0 || majorRadius < R,""); |
147 | minorRadius = R; |
148 | } |
149 | |
150 | inline void gp_Elips::Rotate (const gp_Ax1& A1, |
151 | const Standard_Real Ang) { pos.Rotate(A1, Ang); } |
152 | |
153 | inline gp_Elips gp_Elips::Rotated (const gp_Ax1& A1, |
154 | const Standard_Real Ang) const |
155 | { |
156 | gp_Elips E = *this; |
157 | E.pos.Rotate(A1, Ang); |
158 | return E; |
159 | } |
160 | |
161 | inline void gp_Elips::Scale (const gp_Pnt& P, |
162 | const Standard_Real S) |
163 | // Modified by skv - Fri Apr 8 10:28:10 2005 OCC8559 Begin |
164 | // { pos.Scale(P, S); } |
165 | { |
166 | majorRadius *= S; |
167 | if (majorRadius < 0) majorRadius = - majorRadius; |
168 | minorRadius *= S; |
169 | if (minorRadius < 0) minorRadius = - minorRadius; |
170 | pos.Scale(P, S); |
171 | } |
172 | // Modified by skv - Fri Apr 8 10:28:10 2005 OCC8559 End |
173 | |
174 | inline gp_Elips gp_Elips::Scaled (const gp_Pnt& P, |
175 | const Standard_Real S) const |
176 | { |
177 | gp_Elips E = *this; |
178 | E.majorRadius *= S; |
179 | if (E.majorRadius < 0) E.majorRadius = - E.majorRadius; |
180 | E.minorRadius *= S; |
181 | if (E.minorRadius < 0) E.minorRadius = - E.minorRadius; |
182 | E.pos.Scale(P, S); |
183 | return E; |
184 | } |
185 | |
186 | inline void gp_Elips::Transform (const gp_Trsf& T) |
187 | { |
188 | majorRadius *= T.ScaleFactor(); |
189 | if (majorRadius < 0) majorRadius = - majorRadius; |
190 | minorRadius *= T.ScaleFactor(); |
191 | if (minorRadius < 0) minorRadius = - minorRadius; |
192 | pos.Transform(T); |
193 | } |
194 | |
195 | inline gp_Elips gp_Elips::Transformed (const gp_Trsf& T) const |
196 | { |
197 | gp_Elips E = *this; |
198 | E.majorRadius *= T.ScaleFactor(); |
199 | if (E.majorRadius < 0) E.majorRadius = - E.majorRadius; |
200 | E.minorRadius *= T.ScaleFactor(); |
201 | if (E.minorRadius < 0) E.minorRadius = - E.minorRadius; |
202 | E.pos.Transform(T); |
203 | return E; |
204 | } |
205 | |
206 | inline void gp_Elips::Translate (const gp_Vec& V) |
207 | { pos.Translate(V); } |
208 | |
209 | inline gp_Elips gp_Elips::Translated (const gp_Vec& V) const |
210 | { |
211 | gp_Elips E = *this; |
212 | E.pos.Translate(V); |
213 | return E; |
214 | } |
215 | |
216 | inline void gp_Elips::Translate (const gp_Pnt& P1, |
217 | const gp_Pnt& P2) |
218 | { pos.Translate(P1, P2); } |
219 | |
220 | inline gp_Elips gp_Elips::Translated (const gp_Pnt& P1, |
221 | const gp_Pnt& P2) const |
222 | { |
223 | gp_Elips E = *this; |
224 | E.pos.Translate(P1, P2); |
225 | return E; |
226 | } |
227 | |