0024428: Implementation of LGPL license
[occt.git] / src / GccAna / GccAna_Circ2d3Tan_9.cxx
CommitLineData
b311480e 1// Copyright (c) 1995-1999 Matra Datavision
973c2be1 2// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 3//
973c2be1 4// This file is part of Open CASCADE Technology software library.
b311480e 5//
973c2be1 6// This library is free software; you can redistribute it and / or modify it
7// under the terms of the GNU Lesser General Public version 2.1 as published
8// by the Free Software Foundation, with special exception defined in the file
9// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10// distribution for complete text of the license and disclaimer of any warranty.
b311480e 11//
973c2be1 12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
7fd59977 14
15#include <GccAna_Circ2d3Tan.jxx>
16
17#include <ElCLib.hxx>
18#include <IntAna2d_AnaIntersection.hxx>
19#include <IntAna2d_IntPoint.hxx>
20#include <gp_Lin2d.hxx>
21#include <gp_Circ2d.hxx>
22#include <gp_Dir2d.hxx>
23#include <GccAna_Lin2dBisec.hxx>
24#include <GccEnt_BadQualifier.hxx>
25
26//=========================================================================
0d969553
Y
27// Creation of a circle passing by three points. +
28// Three cases : +
29// 1/ Three points coincide. +
7fd59977 30// ----------------------------------- +
0d969553
Y
31// The result is the circle with center in Point1 with zero radius. +
32// 2/ Two of three points coincide. +
7fd59977 33// ---------------------------------------- +
0d969553
Y
34// Create the medium line between two non-coinciding points and +
35// the straight line passing by these two points. +
36// The center of the solution is the intersection of two straight lines and the +
37// radius is the distance between this center and one of three points. +
38// 3/ The three points are distinct. +
7fd59977 39// ---------------------------------- +
7fd59977 40//=========================================================================
41
42GccAna_Circ2d3Tan::
43 GccAna_Circ2d3Tan (const gp_Pnt2d& Point1 ,
44 const gp_Pnt2d& Point2 ,
45 const gp_Pnt2d& Point3 ,
46 const Standard_Real Tolerance ):
47
48//=========================================================================
0d969553 49// Initialization of fields. +
7fd59977 50//=========================================================================
51
52 cirsol(1,1) ,
53 qualifier1(1,1) ,
54 qualifier2(1,1) ,
55 qualifier3(1,1) ,
56 TheSame1(1,1) ,
57 TheSame2(1,1) ,
58 TheSame3(1,1) ,
59 pnttg1sol(1,1) ,
60 pnttg2sol(1,1) ,
61 pnttg3sol(1,1) ,
62 par1sol(1,1) ,
63 par2sol(1,1) ,
64 par3sol(1,1) ,
65 pararg1(1,1) ,
66 pararg2(1,1) ,
67 pararg3(1,1)
68{
69
70 gp_Dir2d dirx(1.0,0.0);
71 WellDone = Standard_False;
72 NbrSol = 0;
73
74//=========================================================================
0d969553 75// Processing. +
7fd59977 76//=========================================================================
77
78 Standard_Real dist1 = Point1.Distance(Point2);
79 Standard_Real dist2 = Point1.Distance(Point3);
80 Standard_Real dist3 = Point2.Distance(Point3);
81
82 qualifier1(1) = GccEnt_noqualifier;
83 qualifier2(1) = GccEnt_noqualifier;
84 qualifier3(1) = GccEnt_noqualifier;
85
86 if ((dist1 < Tolerance) && (dist2 < Tolerance) && (dist3 < Tolerance)) {
87 NbrSol++;
88 WellDone = Standard_True;
89 cirsol(1) = gp_Circ2d(gp_Ax2d(Point1,dirx),0.0);
90// ===============================================
91 TheSame1(1) = 0;
92 TheSame2(1) = 0;
93 TheSame3(1) = 0;
94 pnttg1sol(1) = Point1;
95 pnttg2sol(1) = Point2;
96 pnttg3sol(1) = Point3;
97 par1sol(1) =0.0;
98 par2sol(1) =0.0;
99 par3sol(1) =0.0;
100 pararg1(1) =0.0;
101 pararg2(1) =0.0;
102 pararg3(1) =0.0;
103 }
104 else {
105 gp_Lin2d L1;
106 gp_Lin2d L2;
107 if (dist1 >= Tolerance) {
108 L1 = gp_Lin2d(gp_Pnt2d((Point1.XY()+Point2.XY())/2.0),
109 gp_Dir2d(Point1.Y()-Point2.Y(),Point2.X()-Point1.X()));
110 }
111 if (dist2 >= Tolerance) {
112 L2 = gp_Lin2d(gp_Pnt2d((Point1.XY()+Point3.XY())/2.0),
113 gp_Dir2d(Point1.Y()-Point3.Y(),Point3.X()-Point1.X()));
114 }
115 if (dist2 <= Tolerance) {
116 L2 = gp_Lin2d(Point1,
117 gp_Dir2d(Point1.Y()-Point2.Y(),Point2.X()-Point1.X()));
118 }
119 else if (dist1 <= Tolerance) {
120 L1 = gp_Lin2d(Point1,
121 gp_Dir2d(Point1.Y()-Point3.Y(),Point3.X()-Point1.X()));
122 }
123 else if (dist3 <= Tolerance) {
124 L2 = gp_Lin2d(Point1,
125 gp_Dir2d(Point1.Y()-Point2.Y(),Point2.X()-Point1.X()));
126 }
127 IntAna2d_AnaIntersection Intp(L1,L2);
128 if (Intp.IsDone()) {
129 if (!Intp.IsEmpty()) {
130 for (Standard_Integer i = 1 ; i <= Intp.NbPoints() ; i++) {
131 NbrSol++;
132 cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(Intp.Point(i).Value(),dirx),
133// ===============================================================
134 Point1.Distance(Intp.Point(i).Value()));
135// =======================================
136
137 TheSame1(NbrSol) = 0;
138 TheSame2(NbrSol) = 0;
139 TheSame3(NbrSol) = 0;
140 pnttg1sol(NbrSol) = Point1;
141 pnttg2sol(NbrSol) = Point2;
142 pnttg3sol(NbrSol) = Point3;
143 par1sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),pnttg1sol(NbrSol));
144 par2sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),pnttg2sol(NbrSol));
145 par3sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),pnttg3sol(NbrSol));
146 pararg1(NbrSol) =0.0;
147 pararg2(NbrSol) =0.0;
148 pararg3(NbrSol) =0.0;
149 }
150 }
151 WellDone = Standard_True;
152 }
153 }
154 }
155