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 STRAIGHT LINE. +
19 //=========================================================================
21 #include <GccAna_CircLin2dBisec.hxx>
22 #include <GccInt_Bisec.hxx>
23 #include <GccInt_BLine.hxx>
24 #include <GccInt_BParab.hxx>
26 #include <gp_Ax2d.hxx>
27 #include <gp_Circ2d.hxx>
28 #include <gp_Dir2d.hxx>
29 #include <gp_Lin2d.hxx>
31 #include <Standard_OutOfRange.hxx>
32 #include <StdFail_NotDone.hxx>
34 //=========================================================================
35 GccAna_CircLin2dBisec::
36 GccAna_CircLin2dBisec (const gp_Circ2d& Circle ,
37 const gp_Lin2d& Line ):
43 //=========================================================================
44 // Initialization of fields : +
46 // - line (straight line.) +
47 // - NbrSol (number of solution.) +
48 // - WellDone (Booleen showing success or failure of algorithm). +
49 //=========================================================================
52 WellDone = Standard_True;
55 //=========================================================================
57 // Return coordinates of origins of the straight line (xloc,yloc) and the +
58 // circle (xcencir, ycencir). +
59 // Also return the coordinates of the direction of the straight line (xdir, +
60 // ydir) and the radius of circle R1. +
61 // Check at which side of the straight line is found the center of the circle +
62 // to orientate the parabola (sign). +
63 // Create axis of each parabola (axeparab1, axeparb2), then +
64 // two parabolas (biscirlin1, biscirlin1). +
65 //=========================================================================
67 Handle(GccInt_Bisec) GccAna_CircLin2dBisec::
68 ThisSolution (const Standard_Integer Index) const
71 if (!WellDone) throw StdFail_NotDone();
73 if ((Index <=0) || (Index > NbrSol)) throw Standard_OutOfRange();
75 Handle(GccInt_Bisec) bissol;
76 Standard_Real xdir = line.Direction().X();
77 Standard_Real ydir = line.Direction().Y();
78 Standard_Real xloc = line.Location().X();
79 Standard_Real yloc = line.Location().Y();
80 Standard_Real xcencir = circle.Location().X();
81 Standard_Real ycencir = circle.Location().Y();
82 Standard_Real R1 = circle.Radius();
83 Standard_Real dist = line.Distance(circle.Location());
84 if ((Abs(line.Distance(circle.Location())-circle.Radius())
85 <= gp::Resolution()) && (Index == 1)) {
86 gp_Lin2d biscirlin1(circle.Location(),gp_Dir2d(-ydir,xdir));
87 bissol = new GccInt_BLine(biscirlin1);
88 // ==========================================================
91 Standard_Integer signe;
92 if ((-ydir*(xcencir-xloc)+xdir*(ycencir-yloc)) > 0.0) {
100 gp_Parab2d biscirlin;
103 axeparab1=gp_Ax2d(gp_Pnt2d(gp_XY(xcencir+signe*ydir*(dist+R1)/2,
104 ycencir-signe*xdir*(dist+R1)/2.)),
105 gp_Dir2d(-signe*ydir,signe*xdir));
106 biscirlin = gp_Parab2d(axeparab1,(dist+R1)/2.0);
110 axeparab1=gp_Ax2d(gp_Pnt2d(gp_XY(xcencir+signe*ydir*(dist-R1)/2,
111 ycencir-signe*xdir*(dist-R1)/2.)),
112 gp_Dir2d(signe*ydir,-signe*xdir));
115 axeparab1=gp_Ax2d(gp_Pnt2d(gp_XY(xcencir+signe*ydir*(dist-R1)/2,
116 ycencir-signe*xdir*(dist-R1)/2.)),
117 gp_Dir2d(-signe*ydir,signe*xdir));
119 biscirlin = gp_Parab2d(axeparab1,Abs(dist-R1)/2.0);
121 bissol = new GccInt_BParab(biscirlin);
122 // ==========================================================
125 axeparab1 = gp_Ax2d(gp_Pnt2d(gp_XY(xcencir+signe*ydir*(dist+R1)/2.,
126 ycencir-signe*xdir*(dist+R1)/2.)),
127 gp_Dir2d(signe*(-ydir),signe*xdir));
128 biscirlin = gp_Parab2d(axeparab1,R1);
129 bissol = new GccInt_BParab(biscirlin);
130 // ==========================================================
137 //=========================================================================
139 Standard_Boolean GccAna_CircLin2dBisec::
140 IsDone () const { return WellDone; }
142 Standard_Integer GccAna_CircLin2dBisec::
143 NbSolutions () const { return NbrSol; }