Commit | Line | Data |
---|---|---|
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 | // |
d5f74e42 | 6 | // This library is free software; you can redistribute it and/or modify it under |
7 | // the terms of the GNU Lesser General Public License version 2.1 as published | |
973c2be1 | 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 | |
7fd59977 | 15 | |
16 | #include <ElCLib.hxx> | |
42cf5bc1 | 17 | #include <GccAna_Circ2d3Tan.hxx> |
7fd59977 | 18 | #include <GccAna_Lin2dBisec.hxx> |
19 | #include <GccEnt_BadQualifier.hxx> | |
42cf5bc1 | 20 | #include <GccEnt_QualifiedCirc.hxx> |
21 | #include <GccEnt_QualifiedLin.hxx> | |
22 | #include <gp_Circ2d.hxx> | |
23 | #include <gp_Dir2d.hxx> | |
24 | #include <gp_Lin2d.hxx> | |
25 | #include <gp_Pnt2d.hxx> | |
26 | #include <IntAna2d_AnaIntersection.hxx> | |
27 | #include <IntAna2d_IntPoint.hxx> | |
28 | #include <Standard_OutOfRange.hxx> | |
29 | #include <StdFail_NotDone.hxx> | |
7fd59977 | 30 | |
31 | //========================================================================= | |
0d969553 Y |
32 | // Creation of a circle passing by three points. + |
33 | // Three cases : + | |
34 | // 1/ Three points coincide. + | |
7fd59977 | 35 | // ----------------------------------- + |
0d969553 Y |
36 | // The result is the circle with center in Point1 with zero radius. + |
37 | // 2/ Two of three points coincide. + | |
7fd59977 | 38 | // ---------------------------------------- + |
0d969553 Y |
39 | // Create the medium line between two non-coinciding points and + |
40 | // the straight line passing by these two points. + | |
41 | // The center of the solution is the intersection of two straight lines and the + | |
42 | // radius is the distance between this center and one of three points. + | |
43 | // 3/ The three points are distinct. + | |
7fd59977 | 44 | // ---------------------------------- + |
7fd59977 | 45 | //========================================================================= |
7fd59977 | 46 | GccAna_Circ2d3Tan:: |
47 | GccAna_Circ2d3Tan (const gp_Pnt2d& Point1 , | |
48 | const gp_Pnt2d& Point2 , | |
49 | const gp_Pnt2d& Point3 , | |
50 | const Standard_Real Tolerance ): | |
51 | ||
52 | //========================================================================= | |
0d969553 | 53 | // Initialization of fields. + |
7fd59977 | 54 | //========================================================================= |
55 | ||
56 | cirsol(1,1) , | |
57 | qualifier1(1,1) , | |
58 | qualifier2(1,1) , | |
59 | qualifier3(1,1) , | |
60 | TheSame1(1,1) , | |
61 | TheSame2(1,1) , | |
62 | TheSame3(1,1) , | |
63 | pnttg1sol(1,1) , | |
64 | pnttg2sol(1,1) , | |
65 | pnttg3sol(1,1) , | |
66 | par1sol(1,1) , | |
67 | par2sol(1,1) , | |
68 | par3sol(1,1) , | |
69 | pararg1(1,1) , | |
70 | pararg2(1,1) , | |
71 | pararg3(1,1) | |
72 | { | |
73 | ||
74 | gp_Dir2d dirx(1.0,0.0); | |
75 | WellDone = Standard_False; | |
76 | NbrSol = 0; | |
77 | ||
78 | //========================================================================= | |
0d969553 | 79 | // Processing. + |
7fd59977 | 80 | //========================================================================= |
81 | ||
82 | Standard_Real dist1 = Point1.Distance(Point2); | |
83 | Standard_Real dist2 = Point1.Distance(Point3); | |
84 | Standard_Real dist3 = Point2.Distance(Point3); | |
85 | ||
86 | qualifier1(1) = GccEnt_noqualifier; | |
87 | qualifier2(1) = GccEnt_noqualifier; | |
88 | qualifier3(1) = GccEnt_noqualifier; | |
89 | ||
90 | if ((dist1 < Tolerance) && (dist2 < Tolerance) && (dist3 < Tolerance)) { | |
91 | NbrSol++; | |
92 | WellDone = Standard_True; | |
93 | cirsol(1) = gp_Circ2d(gp_Ax2d(Point1,dirx),0.0); | |
94 | // =============================================== | |
95 | TheSame1(1) = 0; | |
96 | TheSame2(1) = 0; | |
97 | TheSame3(1) = 0; | |
98 | pnttg1sol(1) = Point1; | |
99 | pnttg2sol(1) = Point2; | |
100 | pnttg3sol(1) = Point3; | |
101 | par1sol(1) =0.0; | |
102 | par2sol(1) =0.0; | |
103 | par3sol(1) =0.0; | |
104 | pararg1(1) =0.0; | |
105 | pararg2(1) =0.0; | |
106 | pararg3(1) =0.0; | |
107 | } | |
108 | else { | |
109 | gp_Lin2d L1; | |
110 | gp_Lin2d L2; | |
111 | if (dist1 >= Tolerance) { | |
112 | L1 = gp_Lin2d(gp_Pnt2d((Point1.XY()+Point2.XY())/2.0), | |
113 | gp_Dir2d(Point1.Y()-Point2.Y(),Point2.X()-Point1.X())); | |
114 | } | |
115 | if (dist2 >= Tolerance) { | |
116 | L2 = gp_Lin2d(gp_Pnt2d((Point1.XY()+Point3.XY())/2.0), | |
117 | gp_Dir2d(Point1.Y()-Point3.Y(),Point3.X()-Point1.X())); | |
118 | } | |
119 | if (dist2 <= Tolerance) { | |
120 | L2 = gp_Lin2d(Point1, | |
121 | gp_Dir2d(Point1.Y()-Point2.Y(),Point2.X()-Point1.X())); | |
122 | } | |
123 | else if (dist1 <= Tolerance) { | |
124 | L1 = gp_Lin2d(Point1, | |
125 | gp_Dir2d(Point1.Y()-Point3.Y(),Point3.X()-Point1.X())); | |
126 | } | |
127 | else if (dist3 <= Tolerance) { | |
128 | L2 = gp_Lin2d(Point1, | |
129 | gp_Dir2d(Point1.Y()-Point2.Y(),Point2.X()-Point1.X())); | |
130 | } | |
131 | IntAna2d_AnaIntersection Intp(L1,L2); | |
132 | if (Intp.IsDone()) { | |
133 | if (!Intp.IsEmpty()) { | |
134 | for (Standard_Integer i = 1 ; i <= Intp.NbPoints() ; i++) { | |
135 | NbrSol++; | |
136 | cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(Intp.Point(i).Value(),dirx), | |
137 | // =============================================================== | |
138 | Point1.Distance(Intp.Point(i).Value())); | |
139 | // ======================================= | |
140 | ||
141 | TheSame1(NbrSol) = 0; | |
142 | TheSame2(NbrSol) = 0; | |
143 | TheSame3(NbrSol) = 0; | |
144 | pnttg1sol(NbrSol) = Point1; | |
145 | pnttg2sol(NbrSol) = Point2; | |
146 | pnttg3sol(NbrSol) = Point3; | |
147 | par1sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),pnttg1sol(NbrSol)); | |
148 | par2sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),pnttg2sol(NbrSol)); | |
149 | par3sol(NbrSol)=ElCLib::Parameter(cirsol(NbrSol),pnttg3sol(NbrSol)); | |
150 | pararg1(NbrSol) =0.0; | |
151 | pararg2(NbrSol) =0.0; | |
152 | pararg3(NbrSol) =0.0; | |
153 | } | |
154 | } | |
155 | WellDone = Standard_True; | |
156 | } | |
157 | } | |
158 | } | |
159 |