0024510: Remove unused local variables
[occt.git] / src / IntCurve / IntCurve_IConicTool.cxx
CommitLineData
b311480e 1// Copyright (c) 1995-1999 Matra Datavision
973c2be1 2// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 3//
973c2be1 4// This file is part of Open CASCADE Technology software library.
b311480e 5//
973c2be1 6// This library is free software; you can redistribute it and / or modify it
7// under the terms of the GNU Lesser General Public 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.
b311480e 11//
973c2be1 12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
b311480e 14
7fd59977 15#include <IntCurve_IConicTool.ixx>
16#include <ElCLib.hxx>
17#include <gp.hxx>
b311480e 18
7fd59977 19
20#define Object_To_Abs Abs_To_Object.Inverted()
21//======================================================================
22#define Elips_a prm1
23#define Elips_b prm2
24#define Elips_c prm3
25
26#define Elips_aa (Elips_a*Elips_a)
27#define Elips_bb (Elips_b*Elips_b)
28#define Elips_x0 (Axis.Location().X())
29#define Elips_y0 (Axis.Location().Y())
30//======================================================================
31#define Hypr_a prm1
32#define Hypr_b prm2
33#define Hypr_aa (Hypr_a * Hypr_a)
34#define Hypr_bb (Hypr_b * Hypr_b)
35//======================================================================
36#define Line_a prm1
37#define Line_b prm2
38#define Line_c prm3
39//======================================================================
40#define Circle_r prm1
41#define Circle_x0 prm2
42#define Circle_y0 prm3
43//======================================================================
44#define Parab_f prm1
45#define Parab_2p prm2
46
47//======================================================================
48IntCurve_IConicTool::IntCurve_IConicTool(void) {
49//###### PLACER LE TYPE NON DEFINI ######
50}
51
52
53IntCurve_IConicTool::IntCurve_IConicTool(const IntCurve_IConicTool& ITool) {
54 prm1=ITool.prm1;
55 prm2=ITool.prm2;
56 prm3=ITool.prm3;
57 Axis=ITool.Axis;
58 Abs_To_Object=ITool.Abs_To_Object;
59 type=ITool.type;
60}
61//======================================================================
62//======================================================================
63IntCurve_IConicTool::IntCurve_IConicTool(const gp_Lin2d& Line) {
64 Line.Coefficients(Line_a,Line_b,Line_c);
65 Axis = gp_Ax22d(Line.Position(),Standard_True);
66 type = GeomAbs_Line;
67}
68//======================================================================
69IntCurve_IConicTool::IntCurve_IConicTool(const gp_Elips2d& Elips) {
70 Elips_a = Elips.MajorRadius();
71 Elips_b = Elips.MinorRadius();
72 Elips_c = sqrt(Elips_a*Elips_a-Elips_b*Elips_b);
73 Axis = Elips.Axis();
74 Abs_To_Object.SetTransformation(gp::OX2d(),Axis.XAxis());
75 type = GeomAbs_Ellipse;
76}
77//======================================================================
78IntCurve_IConicTool::IntCurve_IConicTool(const gp_Circ2d& C) {
79 Circle_r=C.Radius();
80 Axis=C.Axis();
81 Circle_x0=Axis.Location().X();
82 Circle_y0=Axis.Location().Y();
83 Abs_To_Object.SetTransformation(gp::OX2d(),Axis.XAxis());
84 type = GeomAbs_Circle;
85}
86//======================================================================
87IntCurve_IConicTool::IntCurve_IConicTool(const gp_Parab2d& P) {
88 Parab_f=P.Focal();
89 Parab_2p=4.0*Parab_f;
90 Axis=P.Axis();
91 Abs_To_Object.SetTransformation(gp::OX2d(),Axis.XAxis());
92 type = GeomAbs_Parabola;
93}
94//======================================================================
95IntCurve_IConicTool::IntCurve_IConicTool(const gp_Hypr2d& H) {
96 Hypr_a = H.MajorRadius();
97 Hypr_b = H.MinorRadius();
98 Axis = H.Axis();
99 Abs_To_Object.SetTransformation(gp::OX2d(),Axis.XAxis());
100 type = GeomAbs_Hyperbola;
101}
102//----------------------------------------------------------------------
103gp_Pnt2d IntCurve_IConicTool::Value(const Standard_Real X) const {
104 switch(type) {
105 case GeomAbs_Line: return(ElCLib::LineValue(X,Axis.XAxis()));
106 case GeomAbs_Ellipse: return(ElCLib::EllipseValue(X,Axis,Elips_a,Elips_b));
107 case GeomAbs_Circle: return(ElCLib::CircleValue(X,Axis,Circle_r));
108 case GeomAbs_Parabola: return(ElCLib::ParabolaValue(X,Axis,Parab_f));
109 case GeomAbs_Hyperbola: return(ElCLib::HyperbolaValue(X,Axis,Hypr_a,Hypr_b));
110 default: { cout<<"### Erreur sur le type de la courbe ###";
111 return(gp_Pnt2d(0.0,0.0)); }
112 }
113}
114
115//----------------------------------------------------------------------
116void IntCurve_IConicTool::D1(const Standard_Real X,
117 gp_Pnt2d& Pt,
118 gp_Vec2d& Tan) const {
119
120 switch(type) {
121 case GeomAbs_Line: ElCLib::LineD1(X,Axis.XAxis(),Pt,Tan); break;
122 case GeomAbs_Ellipse: ElCLib::EllipseD1(X,Axis,Elips_a,Elips_b,Pt,Tan); break;
123 case GeomAbs_Circle: ElCLib::CircleD1(X,Axis,Circle_r,Pt,Tan); break;
124 case GeomAbs_Parabola: ElCLib::ParabolaD1(X,Axis,Parab_f,Pt,Tan); break;
125 case GeomAbs_Hyperbola: ElCLib::HyperbolaD1(X,Axis,Hypr_a,Hypr_b,Pt,Tan); break;
126 default: { cout<<"### Erreur sur le type de la courbe ###"; }
127 }
128}
129
130//----------------------------------------------------------------------
131void IntCurve_IConicTool::D2(const Standard_Real X,
132 gp_Pnt2d& Pt,
133 gp_Vec2d& Tan,
134 gp_Vec2d& Norm) const {
135
136 switch(type) {
137 case GeomAbs_Line: ElCLib::LineD1(X,Axis.XAxis(),Pt,Tan); Norm.SetCoord(0.0,0.0); break;
138 case GeomAbs_Ellipse: ElCLib::EllipseD2(X,Axis,Elips_a,Elips_b,Pt,Tan,Norm); break;
139 case GeomAbs_Circle: ElCLib::CircleD2(X,Axis,Circle_r,Pt,Tan,Norm); break;
140 case GeomAbs_Parabola: ElCLib::ParabolaD2(X,Axis,Parab_f,Pt,Tan,Norm); break;
141 case GeomAbs_Hyperbola: ElCLib::HyperbolaD2(X,Axis,Hypr_a,Hypr_b,Pt,Tan,Norm); break;
142 default: { cout<<"### Erreur sur le type de la courbe ###"; }
143 }
144}
145//----------------------------------------------------------------------
146#define AN_ELIPS 0
147//----------------------------------------------------------------------
148Standard_Real IntCurve_IConicTool::Distance(const gp_Pnt2d& ThePoint) const {
149
150 switch(type) {
151 case GeomAbs_Line:
152 {
153 return(Line_a*ThePoint.X()+Line_b*ThePoint.Y()+Line_c);
154 }
155
156 case GeomAbs_Ellipse:
157 {
158#if AN_ELIPS
159 gp_Pnt2d P=ThePoint;
160 P.Transform(Abs_To_Object);
161 Standard_Real x=P.X();
162 Standard_Real y2=P.Y() * P.Y();
163 return(sqrt(y2+(x+Elips_c)*(x+Elips_c))
164 +sqrt(y2+(x-Elips_c)*(x-Elips_c))-Elips_a-Elips_a);
165#else
166 gp_Pnt2d P=ThePoint;
167 P.Transform(Abs_To_Object);
168 Standard_Real x=P.X();
169 Standard_Real y=P.Y()*(Elips_a/Elips_b);
170 Standard_Real d=sqrt(x*x+y*y)-Elips_a;
171 return(d);
172#endif
173 }
174
175 case GeomAbs_Circle:
176 {
177 Standard_Real Dx=Circle_x0-ThePoint.X();
178 Standard_Real Dy=Circle_y0-ThePoint.Y();
179 return(sqrt(Dx*Dx+Dy*Dy)-Circle_r);
180 }
181
182 case GeomAbs_Parabola:
183 { //-- Distance(X,Y) = Y**2 - 2 P X
184 gp_Pnt2d P=ThePoint;
185 P.Transform(Abs_To_Object);
186 return(P.Y()*P.Y()-Parab_2p*P.X());
187 }
188
189 case GeomAbs_Hyperbola:
190 { //-- Distance(X,Y) = (X/a)**2 - (Y/b)**2 -1
191 //-- pour x>0
192 //-- -(Y/b)**2 - 1 sinon ??
193 //-- avec un gradient avec x -> Abs(x)
194 gp_Pnt2d P=ThePoint;
195 P.Transform(Abs_To_Object);
196 if(P.X()>0.0)
197 return((P.X()*P.X())/Hypr_aa
198 -(P.Y()*P.Y())/Hypr_bb -1.0);
199 else
200 return((-P.X()*P.X())/Hypr_aa
201 -(P.Y()*P.Y())/Hypr_bb -1.0);
202 }
203 default: { cout<<"### Erreur sur le type de la courbe ###";
204 return(0.0); }
205 }
206}
207
208
209gp_Vec2d IntCurve_IConicTool::GradDistance(const gp_Pnt2d& ThePoint) const {
210
211 switch(type) {
212 case GeomAbs_Line: return(gp_Vec2d(Line_a,Line_b));
213
214 case GeomAbs_Circle: {
215 gp_Pnt2d P=ThePoint;
216 P.Transform(Abs_To_Object);
217 Standard_Real Gradx=0.0;
218 Standard_Real Grady=0.0;
219 Standard_Real x=P.X();
220 Standard_Real y=P.Y();
221 Standard_Real temp1=sqrt(y*y+x*x);
222 if(temp1) {
223 Gradx=x/temp1;
224 Grady=y/temp1;
225 }
226 gp_Vec2d Gradient(Gradx,Grady);
227 Gradient.Transform(Object_To_Abs);
228 return(Gradient);
229 }
230 case GeomAbs_Ellipse: {
231#if AN_ELIPS
232 gp_Pnt2d P=ThePoint;
233 P.Transform(Abs_To_Object);
234 Standard_Real Gradx=0.0;
235 Standard_Real Grady=0.0;
236 Standard_Real x=P.X();
237 Standard_Real y=P.Y();
238 Standard_Real xmc=x-Elips_c;
239 Standard_Real xpc=x+Elips_c;
240 Standard_Real temp1=sqrt(y*y+xmc*xmc);
241 Standard_Real temp2=sqrt(y*y+xpc*xpc);
242 if(temp2) {
243 Gradx=xpc/temp2;
244 Grady=y/temp2;
245 }
246 if(temp1) {
247 Gradx+=xmc/temp1;
248 Grady+=y/temp1;
249 }
250 gp_Vec2d Gradient(Gradx,Grady);
251 Gradient.Transform(Object_To_Abs);
252 return(Gradient);
253#else
254 gp_Pnt2d P=ThePoint;
255 P.Transform(Abs_To_Object);
256 Standard_Real Gradx=0.0;
257 Standard_Real Grady=0.0;
258 Standard_Real x=P.X();
259 Standard_Real y=P.Y()*(Elips_a/Elips_b);
260 Standard_Real temp1=sqrt(y*y+x*x);
261 if(temp1) {
262 Gradx=x/temp1;
263 Grady=(y*(Elips_a/Elips_b))/temp1;
264 }
265 gp_Vec2d Gradient(Gradx,Grady);
266 Gradient.Transform(Object_To_Abs);
267 return(Gradient);
268#endif
269 }
270
271 case GeomAbs_Parabola: { //-- Distance(X,Y) = Y**2 - 2 P X
272 gp_Pnt2d P=ThePoint;
273 P.Transform(Abs_To_Object);
274 gp_Vec2d Gradient(-Parab_2p,P.Y()+P.Y());
275 Gradient.Transform(Object_To_Abs);
276 return(Gradient);
277 }
278 case GeomAbs_Hyperbola: { //-- Distance(X,Y) = (X/a)**2 - (Y/b)**2 -1
279 gp_Pnt2d P=ThePoint;
280 P.Transform(Abs_To_Object);
281 //--### la Branche a X negatif doit ramener vers les X positifs
282 gp_Vec2d Gradient(2.0*Abs(P.X())/Hypr_aa,-2.0*P.Y()/Hypr_bb);
283 Gradient.Transform(Object_To_Abs);
284 return(Gradient);
285 }
286 default: { cout<<"### Erreur sur le type de la courbe ###";
287 return(gp_Vec2d(0.0,0.0)); }
288 }
289}
290
291
292Standard_Real IntCurve_IConicTool::FindParameter(const gp_Pnt2d& P) const {
293
294 Standard_Real Param=0;
295
296 switch(type) {
297
298 case GeomAbs_Line:
299 Param=ElCLib::LineParameter(Axis.XAxis(),P);
300 break;
301
302 case GeomAbs_Circle:
303 Param=ElCLib::CircleParameter(Axis,P);
c6541a0c 304 if(Param<0.0) { Param+=M_PI+M_PI; }
7fd59977 305 break;
306
307 case GeomAbs_Ellipse: {
308 Param=ElCLib::EllipseParameter(Axis
309 ,Elips_a
310 ,Elips_b
311 ,P);
c6541a0c 312 if (Param < 0.0) { Param+=M_PI+M_PI; }
7fd59977 313 break;
314 }
315
316 case GeomAbs_Parabola: {
317 Param=ElCLib::ParabolaParameter(Axis,P);
318 break;
319 }
320 case GeomAbs_Hyperbola: {
321 Param=ElCLib::HyperbolaParameter(Axis
322 ,Hypr_a
323 ,Hypr_b
324 ,P);
325 break;
326 }
7fd59977 327 default:
328 break;
7fd59977 329 }
330
331 return(Param);
332}
333
334