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
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.
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.ixx>
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>
35 //=========================================================================
37 GccAna_CircPnt2dBisec::
38 GccAna_CircPnt2dBisec (const gp_Circ2d& Circle ,
39 const gp_Pnt2d& Point )
47 GccAna_CircPnt2dBisec::
48 GccAna_CircPnt2dBisec (const gp_Circ2d& Circle ,
49 const gp_Pnt2d& Point,
50 const Standard_Real Tolerance)
55 if (myTolerance < Tolerance)
56 myTolerance = Tolerance;
61 void GccAna_CircPnt2dBisec::DefineSolutions()
63 Standard_Real dist = circle.Radius() - point.Distance(circle.Location());
65 if (Abs(dist) < myTolerance)
80 WellDone = Standard_True;
83 //=========================================================================
85 // Return the coordinates of origins of the straight line (xloc,yloc) and+
86 // of the circle (xcencirc, ycencirc). +
87 // Also return the coordinates of the direction of the straight line (xdir, +
88 // ydir) and the radius of circle R1. +
89 // Check at which side of the straight line is found the center of circle +
90 // to orientate the parabola (sign). +
91 // Create axis of each parabola (axeparab1, axeparb2), then +
92 // two parabolas (biscirPnt1, biscirPnt1). +
93 //=========================================================================
95 Handle(GccInt_Bisec) GccAna_CircPnt2dBisec::
96 ThisSolution (const Standard_Integer Index) const
100 StdFail_NotDone::Raise();
102 if ((Index <=0) || (Index > NbrSol))
103 Standard_OutOfRange::Raise();
105 Handle(GccInt_Bisec) bissol;
106 Standard_Real xpoint = point.X();
107 Standard_Real ypoint = point.Y();
108 Standard_Real xcencir = circle.Location().X();
109 Standard_Real ycencir = circle.Location().Y();
110 Standard_Real R1 = circle.Radius();
111 Standard_Real dist = point.Distance(circle.Location());
113 if (dist < myTolerance)
115 gp_Circ2d biscirpnt1(gp_Ax2d(point,gp_Dir2d(1.0,0.0)),R1/2.);
116 bissol = new GccInt_BCirc(biscirpnt1);
117 // ==========================================================
120 gp_Pnt2d center((xpoint+xcencir)/2.,(ypoint+ycencir)/2.);
121 gp_Ax2d majax(center,gp_Dir2d(xpoint-xcencir,ypoint-ycencir));
123 //=========================================================================
124 // The point is inside the circle. +
125 //=========================================================================
127 if (theposition == -1) {
128 gp_Elips2d biscirpnt(majax,R1/2.,Sqrt(R1*R1-dist*dist)/2.);
129 bissol = new GccInt_BElips(biscirpnt);
130 // ===========================================================
133 //=========================================================================
134 // The point is on the circle. +
135 // There is only one solution : straight line passing through point and the center +
137 //=========================================================================
139 else if (theposition == 0) {
141 if (circle.IsDirect())
142 dirsol=gp_Dir2d(xcencir-xpoint,ycencir-ypoint);
143 else dirsol = gp_Dir2d(xpoint-xcencir,ypoint-ycencir);
144 gp_Lin2d biscirpnt(point,dirsol);
145 bissol = new GccInt_BLine(biscirpnt);
146 // =========================================================
149 //=========================================================================
150 // The point is outside of the circle. +
151 // There are two solutions : two main branches of the hyperbola.+
152 //=========================================================================
155 // Standard_Real d1 = sqrt(dist*R1-R1*R1);
156 Standard_Real d1 = sqrt(dist*dist-R1*R1)/2.0;
157 Standard_Real d2 = R1/2.;
159 gp_Hypr2d biscirpnt1(majax,d2,d1);
160 bissol = new GccInt_BHyper(biscirpnt1);
161 // =========================================
164 gp_Hypr2d biscirpnt1(majax,d2,d1);
165 gp_Hypr2d biscirpnt2 = biscirpnt1.OtherBranch();
166 bissol = new GccInt_BHyper(biscirpnt2);
167 // =========================================
175 //=========================================================================
177 Standard_Boolean GccAna_CircPnt2dBisec::
178 IsDone () const { return WellDone; }
180 Standard_Integer GccAna_CircPnt2dBisec::
181 NbSolutions () const { return NbrSol; }