0024510: Remove unused local variables
[occt.git] / src / GccAna / GccAna_CircPnt2dBisec.cxx
CommitLineData
b311480e 1// Created on: 1991-10-11
2// Created by: Remi GILET
3// Copyright (c) 1991-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
973c2be1 8// This library is free software; you can redistribute it and / or modify it
9// under the terms of the GNU Lesser General Public version 2.1 as published
10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
17//=========================================================================
0d969553 18// CREATION of the BISSECTICE between a CIRCLE and a POINT. +
7fd59977 19//=========================================================================
20
21#include <GccAna_CircPnt2dBisec.ixx>
22
23#include <gp_XY.hxx>
24#include <gp_Dir2d.hxx>
25#include <gp_Ax2d.hxx>
26#include <GccInt_BHyper.hxx>
27#include <GccInt_BCirc.hxx>
28#include <GccInt_BElips.hxx>
29#include <GccInt_BLine.hxx>
30#include <Standard_ConstructionError.hxx>
31#include <Standard_OutOfRange.hxx>
32#include <StdFail_NotDone.hxx>
33#include <gp.hxx>
34
35//=========================================================================
36
37GccAna_CircPnt2dBisec::
38 GccAna_CircPnt2dBisec (const gp_Circ2d& Circle ,
39 const gp_Pnt2d& Point ):
40
41 circle(Circle),
42 point(Point) {
43
44//=========================================================================
0d969553
Y
45// Initialization of fields : +
46// - circle ( first argument.) +
47// - line ( second argument.) +
48// - theposition (Integer showing the position of Point +
49// correspondingly to Circle.) +
50// - NbrSol (Integer showing the number of solutions.) +
51// - WellDone (Booleen showing the success or failure of the algorithm). +
7fd59977 52//=========================================================================
53
54 Standard_Real dist = Circle.Radius()-Point.Distance(Circle.Location());
55// if (Abs(dist) < gp::Resolution())
56 if (Abs(dist) < 1.E-10)
57 {
58 theposition = 0;
59 NbrSol = 1;
60 }
61 else if (dist > 0.0)
62 {
63 theposition = -1;
64 NbrSol = 1;
65 }
66 else {
67 theposition = 1;
68 NbrSol = 2;
69 }
70 WellDone = Standard_True;
71 }
72
73//=========================================================================
0d969553
Y
74// Processing. +
75// Return the coordinates of origins of the straight line (xloc,yloc) and+
76// of the circle (xcencirc, ycencirc). +
77// Also return the coordinates of the direction of the straight line (xdir, +
78// ydir) and the radius of circle R1. +
79// Check at which side of the straight line is found the center of circle +
80// to orientate the parabola (sign). +
81// Create axis of each parabola (axeparab1, axeparb2), then +
82// two parabolas (biscirPnt1, biscirPnt1). +
7fd59977 83//=========================================================================
84
85Handle(GccInt_Bisec) GccAna_CircPnt2dBisec::
86 ThisSolution (const Standard_Integer Index) const
87{
88
89 if (!WellDone)
90 StdFail_NotDone::Raise();
91
92 if ((Index <=0) || (Index > NbrSol))
93 Standard_OutOfRange::Raise();
94
95 Handle(GccInt_Bisec) bissol;
96 Standard_Real xpoint = point.X();
97 Standard_Real ypoint = point.Y();
98 Standard_Real xcencir = circle.Location().X();
99 Standard_Real ycencir = circle.Location().Y();
100 Standard_Real R1 = circle.Radius();
101 Standard_Real dist = point.Distance(circle.Location());
102 // if (dist < gp::Resolution())
103 if (dist < 1.E-10)
104 {
105 gp_Circ2d biscirpnt1(gp_Ax2d(point,gp_Dir2d(1.0,0.0)),R1/2.);
106 bissol = new GccInt_BCirc(biscirpnt1);
107 // ==========================================================
108 }
109 else {
110 gp_Pnt2d center((xpoint+xcencir)/2.,(ypoint+ycencir)/2.);
111 gp_Ax2d majax(center,gp_Dir2d(xpoint-xcencir,ypoint-ycencir));
112
113 //=========================================================================
0d969553 114 // The point is inside the circle. +
7fd59977 115 //=========================================================================
116
117 if (theposition == -1) {
118 gp_Elips2d biscirpnt(majax,R1/2.,Sqrt(R1*R1-dist*dist)/2.);
119 bissol = new GccInt_BElips(biscirpnt);
120 // ===========================================================
121 }
122
123 //=========================================================================
0d969553
Y
124 // The point is on the circle. +
125 // There is only one solution : straight line passing through point and the center +
126 // of the circle. +
7fd59977 127 //=========================================================================
128
129 else if (theposition == 0) {
130 gp_Dir2d dirsol;
131 if (circle.IsDirect())
132 dirsol=gp_Dir2d(xcencir-xpoint,ycencir-ypoint);
133 else dirsol = gp_Dir2d(xpoint-xcencir,ypoint-ycencir);
134 gp_Lin2d biscirpnt(point,dirsol);
135 bissol = new GccInt_BLine(biscirpnt);
136 // =========================================================
137 }
138
139 //=========================================================================
0d969553
Y
140 // The point is outside of the circle. +
141 // There are two solutions : two main branches of the hyperbola.+
7fd59977 142 //=========================================================================
143
144 else {
145 // Standard_Real d1 = sqrt(dist*R1-R1*R1);
146 Standard_Real d1 = sqrt(dist*dist-R1*R1)/2.0;
147 Standard_Real d2 = R1/2.;
148 if (Index == 1) {
149 gp_Hypr2d biscirpnt1(majax,d2,d1);
150 bissol = new GccInt_BHyper(biscirpnt1);
151 // =========================================
152 }
153 else {
154 gp_Hypr2d biscirpnt1(majax,d2,d1);
155 gp_Hypr2d biscirpnt2 = biscirpnt1.OtherBranch();
156 bissol = new GccInt_BHyper(biscirpnt2);
157 // =========================================
158 }
159 }
160 }
161 return bissol;
162}
163
164
165//=========================================================================
166
167Standard_Boolean GccAna_CircPnt2dBisec::
168 IsDone () const { return WellDone; }
169
170Standard_Integer GccAna_CircPnt2dBisec::
171 NbSolutions () const { return NbrSol; }
172
173