Integration of OCCT 6.5.0 from SVN
[occt.git] / src / GccAna / GccAna_CircLin2dBisec.cxx
CommitLineData
7fd59977 1// File: GccAna_CircLin2dBisec.cxx
2// Created: Fri Oct 11 08:19:14 1991
3// Author: Remi GILET
4// <reg@topsn3>
5
6//=========================================================================
7// CREATION DE LA BISSECTICE ENTRE UN CERCLE ET UNE DROITE. +
8//=========================================================================
9
10#include <GccAna_CircLin2dBisec.ixx>
11
12#include <gp_XY.hxx>
13#include <gp_Dir2d.hxx>
14#include <gp_Ax2d.hxx>
15#include <GccInt_BParab.hxx>
16#include <GccInt_BLine.hxx>
17#include <Standard_OutOfRange.hxx>
18#include <StdFail_NotDone.hxx>
19#include <gp.hxx>
20
21//=========================================================================
22
23GccAna_CircLin2dBisec::
24 GccAna_CircLin2dBisec (const gp_Circ2d& Circle ,
25 const gp_Lin2d& Line ):
26
27 circle(Circle),
28 line(Line)
29{
30
31//=========================================================================
32// Initialisation des champs : +
33// - circle (Le cercle.) +
34// - line (la droite.) +
35// - NbrSol (nombre de solution.) +
36// - WellDone (Booleen indiquant le succes ou non de l algo.). +
37//=========================================================================
38
39 NbrSol = 2;
40 WellDone = Standard_True;
41 }
42
43//=========================================================================
44// Traitement. +
45// On recupere les coordonees des origines de la droite (xloc,yloc) et +
46// du cercle (xcencir, ycencir). +
47// On recupere aussi les coordonees dela direction de la droite (xdir, +
48// ydir) et le rayon du cercle R1. +
49// On regarde de quel cote de la droite se trouve le centre du cercle +
50// pour orienter la parabole (signe). +
51// On cree l axe de chacune des paraboles (axeparab1, axeparb2), puis +
52// les deux paraboles (biscirlin1, biscirlin1). +
53//=========================================================================
54
55Handle(GccInt_Bisec) GccAna_CircLin2dBisec::
56 ThisSolution (const Standard_Integer Index) const
57{
58
59 if (!WellDone) StdFail_NotDone::Raise();
60
61 if ((Index <=0) || (Index > NbrSol)) Standard_OutOfRange::Raise();
62
63 Handle(GccInt_Bisec) bissol;
64 Standard_Real xdir = line.Direction().X();
65 Standard_Real ydir = line.Direction().Y();
66 Standard_Real xloc = line.Location().X();
67 Standard_Real yloc = line.Location().Y();
68 Standard_Real xcencir = circle.Location().X();
69 Standard_Real ycencir = circle.Location().Y();
70 Standard_Real R1 = circle.Radius();
71 Standard_Real dist = line.Distance(circle.Location());
72 if ((Abs(line.Distance(circle.Location())-circle.Radius())
73 <= gp::Resolution()) && (Index == 1)) {
74 gp_Lin2d biscirlin1(circle.Location(),gp_Dir2d(-ydir,xdir));
75 bissol = new GccInt_BLine(biscirlin1);
76 // ==========================================================
77 }
78 else {
79 Standard_Integer signe;
80 if ((-ydir*(xcencir-xloc)+xdir*(ycencir-yloc)) > 0.0) {
81 signe = 1;
82 }
83 else {
84 signe = -1;
85 }
86 gp_Ax2d axeparab1;
87// gp_Ax2d axeparab2;
88 gp_Parab2d biscirlin;
89 if (dist != R1) {
90 if (Index == 1) {
91 axeparab1=gp_Ax2d(gp_Pnt2d(gp_XY(xcencir+signe*ydir*(dist+R1)/2,
92 ycencir-signe*xdir*(dist+R1)/2.)),
93 gp_Dir2d(-signe*ydir,signe*xdir));
94 biscirlin = gp_Parab2d(axeparab1,(dist+R1)/2.0);
95 }
96 else {
97 if (dist < R1) {
98 axeparab1=gp_Ax2d(gp_Pnt2d(gp_XY(xcencir+signe*ydir*(dist-R1)/2,
99 ycencir-signe*xdir*(dist-R1)/2.)),
100 gp_Dir2d(signe*ydir,-signe*xdir));
101 }
102 else {
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 }
107 biscirlin = gp_Parab2d(axeparab1,Abs(dist-R1)/2.0);
108 }
109 bissol = new GccInt_BParab(biscirlin);
110 // ==========================================================
111 }
112 else {
113 axeparab1 = gp_Ax2d(gp_Pnt2d(gp_XY(xcencir+signe*ydir*(dist+R1)/2.,
114 ycencir-signe*xdir*(dist+R1)/2.)),
115 gp_Dir2d(signe*(-ydir),signe*xdir));
116 biscirlin = gp_Parab2d(axeparab1,R1);
117 bissol = new GccInt_BParab(biscirlin);
118 // ==========================================================
119 }
120 }
121
122 return bissol;
123}
124
125//=========================================================================
126
127Standard_Boolean GccAna_CircLin2dBisec::
128 IsDone () const { return WellDone; }
129
130Standard_Integer GccAna_CircLin2dBisec::
131 NbSolutions () const { return NbrSol; }
132
133