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 | // |
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. | |
b311480e | 14 | |
7fd59977 | 15 | #include <GccAna_Circ2dTanOnRad.jxx> |
16 | ||
17 | #include <ElCLib.hxx> | |
18 | #include <IntAna2d_AnaIntersection.hxx> | |
19 | #include <IntAna2d_IntPoint.hxx> | |
20 | #include <Standard_NegativeValue.hxx> | |
21 | #include <Standard_OutOfRange.hxx> | |
22 | #include <gp_Dir2d.hxx> | |
23 | ||
24 | //========================================================================= | |
0d969553 Y |
25 | // Circle tangent to a point Point1. + |
26 | // center on circle OnCirc. + | |
27 | // radius Radius. + | |
7fd59977 | 28 | // + |
0d969553 Y |
29 | // Initialize the table of solutions cirsol and all fields. + |
30 | // Eliminate cases not being the solution. + | |
31 | // Create the circle with center in Point1 of radius Radius. + | |
32 | // Intersect this circle with OnCirc and obtain the center points + | |
33 | // of found solutions. + | |
34 | // Create solutions cirsol. + | |
7fd59977 | 35 | //========================================================================= |
36 | ||
37 | GccAna_Circ2dTanOnRad:: | |
38 | GccAna_Circ2dTanOnRad (const gp_Pnt2d& Point1 , | |
39 | const gp_Circ2d& OnCirc , | |
40 | const Standard_Real Radius , | |
41 | const Standard_Real Tolerance ): | |
42 | cirsol(1,2) , | |
43 | qualifier1(1,2) , | |
44 | TheSame1(1,2) , | |
45 | pnttg1sol(1,2), | |
46 | pntcen3(1,2) , | |
47 | par1sol(1,2) , | |
48 | pararg1(1,2) , | |
49 | parcen3(1,2) | |
50 | { | |
51 | ||
52 | gp_Dir2d dirx(1.0,0.0); | |
53 | Standard_Real Tol = Abs(Tolerance); | |
54 | WellDone = Standard_False; | |
55 | NbrSol = 0; | |
56 | Standard_Real Roncirc = OnCirc.Radius(); | |
57 | Standard_Real dist1 = Point1.Distance(OnCirc.Location())-Roncirc; | |
58 | Standard_Real dist2 = Point1.Distance(OnCirc.Location())+Roncirc; | |
59 | ||
60 | if (Radius < 0.0) { Standard_NegativeValue::Raise(); } | |
61 | else if ((dist1-Radius > Tol) || (Tol < Radius-dist2)) { | |
62 | WellDone = Standard_True; | |
63 | } | |
64 | else { | |
65 | Standard_Integer signe = 0; | |
66 | if (Abs(dist1-Radius) < Tol) { signe = 1; } | |
67 | else if (Abs(dist2-Radius) < Tol) { signe = -1; } | |
68 | if (signe != 0) { | |
69 | gp_Ax2d axe(gp_Pnt2d(OnCirc.Location().XY()-Roncirc* | |
70 | gp_Dir2d(OnCirc.Location().X()-signe*Point1.X(), | |
71 | OnCirc.Location().Y()-signe*Point1.Y()).XY()),dirx); | |
72 | cirsol(1) = gp_Circ2d(axe,Radius); | |
73 | // ================================ | |
74 | qualifier1(1) = GccEnt_noqualifier; | |
75 | TheSame1(1) = 0; | |
76 | pnttg1sol(1) = Point1; | |
77 | pntcen3(1) = cirsol(1).Location(); | |
78 | pararg1(1) = 0.0; | |
79 | par1sol(1)=ElCLib::Parameter(cirsol(1),pnttg1sol(1)); | |
80 | parcen3(1) = ElCLib::Parameter(OnCirc,pntcen3(1)); | |
81 | WellDone = Standard_True; | |
82 | NbrSol = 1; | |
83 | } | |
84 | else { | |
85 | IntAna2d_AnaIntersection Intp(OnCirc,gp_Circ2d(gp_Ax2d(Point1,dirx), | |
86 | Radius)); | |
87 | if (Intp.IsDone()) { | |
88 | if (!Intp.IsEmpty()) { | |
89 | for (Standard_Integer i = 1 ; i <= Intp.NbPoints() ; i++) { | |
90 | NbrSol++; | |
91 | gp_Pnt2d Center(Intp.Point(i).Value()); | |
92 | cirsol(NbrSol) = gp_Circ2d(gp_Ax2d(Center,dirx),Radius); | |
93 | // ======================================================= | |
94 | qualifier1(1) = GccEnt_noqualifier; | |
95 | TheSame1(1) = 0; | |
96 | pnttg1sol(1) = Point1; | |
97 | pntcen3(1) = cirsol(1).Location(); | |
98 | par1sol(1)=ElCLib::Parameter(cirsol(1),pnttg1sol(1)); | |
99 | parcen3(1) = ElCLib::Parameter(OnCirc,pntcen3(1)); | |
100 | pararg1(1) = 0.0; | |
101 | } | |
102 | } | |
103 | WellDone = Standard_True; | |
104 | } | |
105 | } | |
106 | } | |
107 | } |