1 // Created on: 1991-10-11
2 // Created by: Remi GILET
3 // Copyright (c) 1991-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License 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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 //=========================================================================
18 // CREATION of the BISSECTICE between a CIRCLE and a POINT. +
19 //=========================================================================
21 #include <GccAna_CircPnt2dBisec.hxx>
22 #include <GccInt_BCirc.hxx>
23 #include <GccInt_BElips.hxx>
24 #include <GccInt_BHyper.hxx>
25 #include <GccInt_Bisec.hxx>
26 #include <GccInt_BLine.hxx>
28 #include <gp_Ax2d.hxx>
29 #include <gp_Circ2d.hxx>
30 #include <gp_Dir2d.hxx>
31 #include <gp_Pnt2d.hxx>
33 #include <Standard_ConstructionError.hxx>
34 #include <Standard_OutOfRange.hxx>
35 #include <StdFail_NotDone.hxx>
37 //=========================================================================
38 GccAna_CircPnt2dBisec::
39 GccAna_CircPnt2dBisec (const gp_Circ2d& Circle ,
40 const gp_Pnt2d& Point )
48 GccAna_CircPnt2dBisec::
49 GccAna_CircPnt2dBisec (const gp_Circ2d& Circle ,
50 const gp_Pnt2d& Point,
51 const Standard_Real Tolerance)
56 if (myTolerance < Tolerance)
57 myTolerance = Tolerance;
62 void GccAna_CircPnt2dBisec::DefineSolutions()
64 Standard_Real dist = circle.Radius() - point.Distance(circle.Location());
66 if (Abs(dist) < myTolerance)
81 WellDone = Standard_True;
84 //=========================================================================
86 // Return the coordinates of origins of the straight line (xloc,yloc) and+
87 // of the circle (xcencirc, ycencirc). +
88 // Also return the coordinates of the direction of the straight line (xdir, +
89 // ydir) and the radius of circle R1. +
90 // Check at which side of the straight line is found the center of circle +
91 // to orientate the parabola (sign). +
92 // Create axis of each parabola (axeparab1, axeparb2), then +
93 // two parabolas (biscirPnt1, biscirPnt1). +
94 //=========================================================================
96 Handle(GccInt_Bisec) GccAna_CircPnt2dBisec::
97 ThisSolution (const Standard_Integer Index) const
101 throw StdFail_NotDone();
103 if ((Index <=0) || (Index > NbrSol))
104 throw Standard_OutOfRange();
106 Handle(GccInt_Bisec) bissol;
107 Standard_Real xpoint = point.X();
108 Standard_Real ypoint = point.Y();
109 Standard_Real xcencir = circle.Location().X();
110 Standard_Real ycencir = circle.Location().Y();
111 Standard_Real R1 = circle.Radius();
112 Standard_Real dist = point.Distance(circle.Location());
114 if (dist < myTolerance)
116 gp_Circ2d biscirpnt1(gp_Ax2d(point,gp_Dir2d(1.0,0.0)),R1/2.);
117 bissol = new GccInt_BCirc(biscirpnt1);
118 // ==========================================================
121 gp_Pnt2d center((xpoint+xcencir)/2.,(ypoint+ycencir)/2.);
122 gp_Ax2d majax(center,gp_Dir2d(xpoint-xcencir,ypoint-ycencir));
124 //=========================================================================
125 // The point is inside the circle. +
126 //=========================================================================
128 if (theposition == -1) {
129 gp_Elips2d biscirpnt(majax,R1/2.,Sqrt(R1*R1-dist*dist)/2.);
130 bissol = new GccInt_BElips(biscirpnt);
131 // ===========================================================
134 //=========================================================================
135 // The point is on the circle. +
136 // There is only one solution : straight line passing through point and the center +
138 //=========================================================================
140 else if (theposition == 0) {
142 if (circle.IsDirect())
143 dirsol=gp_Dir2d(xcencir-xpoint,ycencir-ypoint);
144 else dirsol = gp_Dir2d(xpoint-xcencir,ypoint-ycencir);
145 gp_Lin2d biscirpnt(point,dirsol);
146 bissol = new GccInt_BLine(biscirpnt);
147 // =========================================================
150 //=========================================================================
151 // The point is outside of the circle. +
152 // There are two solutions : two main branches of the hyperbola.+
153 //=========================================================================
156 // Standard_Real d1 = sqrt(dist*R1-R1*R1);
157 Standard_Real d1 = sqrt(dist*dist-R1*R1)/2.0;
158 Standard_Real d2 = R1/2.;
160 gp_Hypr2d biscirpnt1(majax,d2,d1);
161 bissol = new GccInt_BHyper(biscirpnt1);
162 // =========================================
165 gp_Hypr2d biscirpnt1(majax,d2,d1);
166 gp_Hypr2d biscirpnt2 = biscirpnt1.OtherBranch();
167 bissol = new GccInt_BHyper(biscirpnt2);
168 // =========================================
176 //=========================================================================
178 Standard_Boolean GccAna_CircPnt2dBisec::
179 IsDone () const { return WellDone; }
181 Standard_Integer GccAna_CircPnt2dBisec::
182 NbSolutions () const { return NbrSol; }