0024428: Implementation of LGPL license
[occt.git] / src / GccAna / GccAna_Circ2d2TanOn_3.cxx
CommitLineData
b311480e 1// Created on: 1992-01-02
2// Created by: Remi GILET
3// Copyright (c) 1992-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#include <GccAna_Circ2d2TanOn.jxx>
18
19#include <ElCLib.hxx>
20#include <gp_Dir2d.hxx>
21#include <gp_Ax2d.hxx>
22#include <IntAna2d_AnaIntersection.hxx>
23#include <IntAna2d_IntPoint.hxx>
24#include <GccInt_IType.hxx>
25#include <GccInt_Bisec.hxx>
26#include <GccInt_BLine.hxx>
27#include <GccInt_BCirc.hxx>
28#include <IntAna2d_Conic.hxx>
29#include <GccAna_CircPnt2dBisec.hxx>
30#include <TColStd_Array1OfReal.hxx>
31#include <GccEnt_BadQualifier.hxx>
32
33//=========================================================================
0d969553
Y
34// Circles tangent to circle C1, passing by point Point2 and centers +
35// on a straight line OnLine. +
36// We start by making difference with boundary cases that will be +
37// processed separately. +
38// For the general case: +
7fd59977 39// ==================== +
0d969553
Y
40// We calculate bissectrices to C1 and Point2 that give us all +
41// possible locations of centers of all circles +
42// tangent to C1 and passing by Point2. +
43// We intersect these bissectrices with the straight line OnLine which +
44// gives us the points among which we'll choose the solutions. +
45// The choices are made using Qualifiers of C1 and C2. +
7fd59977 46//=========================================================================
47
48GccAna_Circ2d2TanOn::
49 GccAna_Circ2d2TanOn (const GccEnt_QualifiedCirc& Qualified1 ,
50 const gp_Pnt2d& Point2 ,
51 const gp_Lin2d& OnLine ,
52 const Standard_Real Tolerance ):
53 cirsol(1,4),
54 qualifier1(1,4) ,
55 qualifier2(1,4) ,
56 TheSame1(1,4) ,
57 TheSame2(1,4) ,
58 pnttg1sol(1,4) ,
59 pnttg2sol(1,4) ,
60 pntcen(1,4) ,
61 par1sol(1,4) ,
62 par2sol(1,4) ,
63 pararg1(1,4) ,
64 pararg2(1,4) ,
65 parcen3(1,4)
66{
67 TheSame1.Init(0);
68 TheSame2.Init(0);
69 Standard_Real Tol = Abs(Tolerance);
70 WellDone = Standard_False;
71 NbrSol = 0;
72 if (!(Qualified1.IsEnclosed() || Qualified1.IsEnclosing() ||
73 Qualified1.IsOutside() || Qualified1.IsUnqualified())) {
74 GccEnt_BadQualifier::Raise();
75 return;
76 }
77 TColStd_Array1OfReal Radius(1,2);
78 gp_Dir2d dirx(1.,0.);
79 gp_Circ2d C1 = Qualified1.Qualified();
80 Standard_Real R1 = C1.Radius();
81 gp_Pnt2d center1(C1.Location());
82
83//=========================================================================
0d969553 84// Processing of boundary cases. +
7fd59977 85//=========================================================================
86
87 Standard_Real dp2l = OnLine.Distance(Point2);
88 gp_Dir2d donline(OnLine.Direction());
89 gp_Pnt2d pinterm(Point2.XY()+dp2l*gp_XY(-donline.Y(),donline.X()));
90 if (OnLine.Distance(pinterm) > Tol) {
91 pinterm = gp_Pnt2d(Point2.XY()-dp2l*gp_XY(-donline.Y(),donline.X()));
92 }
93 Standard_Real dist = pinterm.Distance(center1);
94 if (Qualified1.IsEnclosed() && Abs(R1-dist-dp2l) <= Tol) {
95 WellDone = Standard_True;
96 }
97 else if (Qualified1.IsEnclosing() && Abs(R1+dist-dp2l) <= Tol) {
98 WellDone = Standard_True;
99 }
100 else if (Qualified1.IsOutside() && Abs(dist-dp2l) <= Tol) {
101 WellDone = Standard_True;
102 }
103 else if (Qualified1.IsUnqualified() &&
104 (Abs(dist-dp2l) <= Tol || Abs(R1-dist-dp2l) <= Tol ||
105 Abs(R1+dist-dp2l) <= Tol)) {
106 WellDone = Standard_True;
107 }
108 if (WellDone) {
109 NbrSol++;
110 cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(pinterm,dirx),dp2l);
111// ======================================================
112 gp_Dir2d dc1(center1.XY()-pinterm.XY());
113 Standard_Real distcc1 = pinterm.Distance(center1);
114 if (!Qualified1.IsUnqualified()) {
115 qualifier1(NbrSol) = Qualified1.Qualifier();
116 }
117 else if (Abs(distcc1+dp2l-R1) < Tol) {
118 qualifier1(NbrSol) = GccEnt_enclosed;
119 }
120 else if (Abs(distcc1-R1-dp2l) < Tol) {
121 qualifier1(NbrSol) = GccEnt_outside;
122 }
123 else { qualifier1(NbrSol) = GccEnt_enclosing; }
124 qualifier2(NbrSol) = GccEnt_noqualifier;
125 pnttg1sol(NbrSol) = gp_Pnt2d(pinterm.XY()+dp2l*dc1.XY());
126 par1sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),pnttg1sol(NbrSol));
127 pararg1(NbrSol)=ElCLib::Parameter(C1,pnttg1sol(NbrSol));
128 pnttg2sol(NbrSol) = Point2;
129 par2sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),pnttg2sol(NbrSol));
130 pntcen(NbrSol) = cirsol(NbrSol).Location();
131 parcen3(NbrSol)=ElCLib::Parameter(OnLine,pntcen(NbrSol));
132 return;
133 }
134
135//=========================================================================
0d969553 136// General case. +
7fd59977 137//=========================================================================
138
139 GccAna_CircPnt2dBisec Bis(C1,Point2);
140 if (Bis.IsDone()) {
141 Standard_Integer nbsolution = Bis.NbSolutions();
142 for (Standard_Integer i = 1 ; i <= nbsolution; i++) {
143 Handle(GccInt_Bisec) Sol = Bis.ThisSolution(i);
144 GccInt_IType type = Sol->ArcType();
145 IntAna2d_AnaIntersection Intp;
146 if (type == GccInt_Lin) {
147 Intp.Perform(OnLine,Sol->Line());
148 }
149 else if (type == GccInt_Cir) {
150 Intp.Perform(OnLine,Sol->Circle());
151 }
152 else if (type == GccInt_Ell) {
153 Intp.Perform(OnLine,IntAna2d_Conic(Sol->Ellipse()));
154 }
155 else if (type == GccInt_Hpr) {
156 Intp.Perform(OnLine,IntAna2d_Conic(Sol->Hyperbola()));
157 }
158 if (Intp.IsDone()) {
159 if (!Intp.IsEmpty()) {
160 for (Standard_Integer j = 1 ; j <= Intp.NbPoints() ; j++) {
161 gp_Pnt2d Center(Intp.Point(j).Value());
162 Standard_Real dist1 = center1.Distance(Center);
163 Standard_Integer nbsol = 1;
164 Standard_Boolean ok = Standard_False;
165 if (Qualified1.IsEnclosed()) {
166 if (dist1-C1.Radius() <= Tolerance) {
167 ok = Standard_True;
168 Radius(1) = Abs(C1.Radius()-dist1);
169 }
170 }
171 else if (Qualified1.IsOutside()) {
172 if (C1.Radius()-dist1 <= Tolerance) {
173 ok = Standard_True;
174 Radius(1) = Abs(C1.Radius()-dist1);
175 }
176 }
177 else if (Qualified1.IsEnclosing()) {
178 ok = Standard_True;
179 Radius(1) = C1.Radius()+dist1;
180 }
181/* else if (Qualified1.IsUnqualified() && ok) {
182 ok = Standard_True;
183 nbsol = 2;
184 Radius(1) = Abs(C1.Radius()-dist1);
185 Radius(2) = C1.Radius()+dist1;
186 }
187*/
188 else if (Qualified1.IsUnqualified() ) {
189 Standard_Real popradius = Center.Distance(Point2);
190 if (Abs(popradius-dist1)) {
191 ok = Standard_True;
192 Radius(1) = popradius;
193 }
194 }
195
196 if (ok) {
197 for (Standard_Integer k = 1 ; k <= nbsol ; k++) {
198 NbrSol++;
199 cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(Center,dirx),Radius(k));
200// ==========================================================
201 Standard_Real distcc1 = Center.Distance(center1);
202 if (!Qualified1.IsUnqualified()) {
203 qualifier1(NbrSol) = Qualified1.Qualifier();
204 }
205 else if (Abs(distcc1+Radius(k)-R1) < Tol) {
206 qualifier1(NbrSol) = GccEnt_enclosed;
207 }
208 else if (Abs(distcc1-R1-Radius(k)) < Tol) {
209 qualifier1(NbrSol) = GccEnt_outside;
210 }
211 else { qualifier1(NbrSol) = GccEnt_enclosing; }
212 qualifier2(NbrSol) = GccEnt_noqualifier;
213 if (Center.Distance(center1) <= Tolerance &&
214 Abs(Radius(k)-C1.Radius()) <= Tolerance) {
215 TheSame1(NbrSol) = 1;
216 }
217 else {
218 TheSame1(NbrSol) = 0;
219 gp_Dir2d dc1(center1.XY()-Center.XY());
220 pnttg1sol(NbrSol)=gp_Pnt2d(Center.XY()+Radius(k)*dc1.XY());
221 par1sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
222 pnttg1sol(NbrSol));
223 pararg1(i)=ElCLib::Parameter(C1,pnttg1sol(NbrSol));
224 }
225 TheSame2(NbrSol) = 0;
226 pnttg2sol(NbrSol) = Point2;
227 par2sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),
228 pnttg2sol(NbrSol));
229 pararg2(NbrSol)=0.;
230 pntcen(NbrSol) = Center;
231 parcen3(NbrSol)=ElCLib::Parameter(OnLine,pntcen(NbrSol));
232 }
233 }
234 }
235 }
236 WellDone = Standard_True;
237 }
238 }
239 }
240}