Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1991-10-11 |
2 | // Created by: Remi GILET | |
3 | // Copyright (c) 1991-1999 Matra Datavision | |
4 | // Copyright (c) 1999-2012 OPEN CASCADE SAS | |
5 | // | |
6 | // The content of this file is subject to the Open CASCADE Technology Public | |
7 | // License Version 6.5 (the "License"). You may not use the content of this file | |
8 | // except in compliance with the License. Please obtain a copy of the License | |
9 | // at http://www.opencascade.org and read it completely before using this file. | |
10 | // | |
11 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its | |
12 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. | |
13 | // | |
14 | // The Original Code and all software distributed under the License is | |
15 | // distributed on an "AS IS" basis, without warranty of any kind, and the | |
16 | // Initial Developer hereby disclaims all such warranties, including without | |
17 | // limitation, any warranties of merchantability, fitness for a particular | |
18 | // purpose or non-infringement. Please see the License for the specific terms | |
19 | // and conditions governing the rights and limitations under the License. | |
20 | ||
7fd59977 | 21 | |
22 | //========================================================================= | |
0d969553 | 23 | // CREATION of the BISSECTICE between a CIRCLE and a POINT. + |
7fd59977 | 24 | //========================================================================= |
25 | ||
26 | #include <GccAna_CircPnt2dBisec.ixx> | |
27 | ||
28 | #include <gp_XY.hxx> | |
29 | #include <gp_Dir2d.hxx> | |
30 | #include <gp_Ax2d.hxx> | |
31 | #include <GccInt_BHyper.hxx> | |
32 | #include <GccInt_BCirc.hxx> | |
33 | #include <GccInt_BElips.hxx> | |
34 | #include <GccInt_BLine.hxx> | |
35 | #include <Standard_ConstructionError.hxx> | |
36 | #include <Standard_OutOfRange.hxx> | |
37 | #include <StdFail_NotDone.hxx> | |
38 | #include <gp.hxx> | |
39 | ||
40 | //========================================================================= | |
41 | ||
42 | GccAna_CircPnt2dBisec:: | |
43 | GccAna_CircPnt2dBisec (const gp_Circ2d& Circle , | |
44 | const gp_Pnt2d& Point ): | |
45 | ||
46 | circle(Circle), | |
47 | point(Point) { | |
48 | ||
49 | //========================================================================= | |
0d969553 Y |
50 | // Initialization of fields : + |
51 | // - circle ( first argument.) + | |
52 | // - line ( second argument.) + | |
53 | // - theposition (Integer showing the position of Point + | |
54 | // correspondingly to Circle.) + | |
55 | // - NbrSol (Integer showing the number of solutions.) + | |
56 | // - WellDone (Booleen showing the success or failure of the algorithm). + | |
7fd59977 | 57 | //========================================================================= |
58 | ||
59 | Standard_Real dist = Circle.Radius()-Point.Distance(Circle.Location()); | |
60 | // if (Abs(dist) < gp::Resolution()) | |
61 | if (Abs(dist) < 1.E-10) | |
62 | { | |
63 | theposition = 0; | |
64 | NbrSol = 1; | |
65 | } | |
66 | else if (dist > 0.0) | |
67 | { | |
68 | theposition = -1; | |
69 | NbrSol = 1; | |
70 | } | |
71 | else { | |
72 | theposition = 1; | |
73 | NbrSol = 2; | |
74 | } | |
75 | WellDone = Standard_True; | |
76 | } | |
77 | ||
78 | //========================================================================= | |
0d969553 Y |
79 | // Processing. + |
80 | // Return the coordinates of origins of the straight line (xloc,yloc) and+ | |
81 | // of the circle (xcencirc, ycencirc). + | |
82 | // Also return the coordinates of the direction of the straight line (xdir, + | |
83 | // ydir) and the radius of circle R1. + | |
84 | // Check at which side of the straight line is found the center of circle + | |
85 | // to orientate the parabola (sign). + | |
86 | // Create axis of each parabola (axeparab1, axeparb2), then + | |
87 | // two parabolas (biscirPnt1, biscirPnt1). + | |
7fd59977 | 88 | //========================================================================= |
89 | ||
90 | Handle(GccInt_Bisec) GccAna_CircPnt2dBisec:: | |
91 | ThisSolution (const Standard_Integer Index) const | |
92 | { | |
93 | ||
94 | if (!WellDone) | |
95 | StdFail_NotDone::Raise(); | |
96 | ||
97 | if ((Index <=0) || (Index > NbrSol)) | |
98 | Standard_OutOfRange::Raise(); | |
99 | ||
100 | Handle(GccInt_Bisec) bissol; | |
101 | Standard_Real xpoint = point.X(); | |
102 | Standard_Real ypoint = point.Y(); | |
103 | Standard_Real xcencir = circle.Location().X(); | |
104 | Standard_Real ycencir = circle.Location().Y(); | |
105 | Standard_Real R1 = circle.Radius(); | |
106 | Standard_Real dist = point.Distance(circle.Location()); | |
107 | // if (dist < gp::Resolution()) | |
108 | if (dist < 1.E-10) | |
109 | { | |
110 | gp_Circ2d biscirpnt1(gp_Ax2d(point,gp_Dir2d(1.0,0.0)),R1/2.); | |
111 | bissol = new GccInt_BCirc(biscirpnt1); | |
112 | // ========================================================== | |
113 | } | |
114 | else { | |
115 | gp_Pnt2d center((xpoint+xcencir)/2.,(ypoint+ycencir)/2.); | |
116 | gp_Ax2d majax(center,gp_Dir2d(xpoint-xcencir,ypoint-ycencir)); | |
117 | ||
118 | //========================================================================= | |
0d969553 | 119 | // The point is inside the circle. + |
7fd59977 | 120 | //========================================================================= |
121 | ||
122 | if (theposition == -1) { | |
123 | gp_Elips2d biscirpnt(majax,R1/2.,Sqrt(R1*R1-dist*dist)/2.); | |
124 | bissol = new GccInt_BElips(biscirpnt); | |
125 | // =========================================================== | |
126 | } | |
127 | ||
128 | //========================================================================= | |
0d969553 Y |
129 | // The point is on the circle. + |
130 | // There is only one solution : straight line passing through point and the center + | |
131 | // of the circle. + | |
7fd59977 | 132 | //========================================================================= |
133 | ||
134 | else if (theposition == 0) { | |
135 | gp_Dir2d dirsol; | |
136 | if (circle.IsDirect()) | |
137 | dirsol=gp_Dir2d(xcencir-xpoint,ycencir-ypoint); | |
138 | else dirsol = gp_Dir2d(xpoint-xcencir,ypoint-ycencir); | |
139 | gp_Lin2d biscirpnt(point,dirsol); | |
140 | bissol = new GccInt_BLine(biscirpnt); | |
141 | // ========================================================= | |
142 | } | |
143 | ||
144 | //========================================================================= | |
0d969553 Y |
145 | // The point is outside of the circle. + |
146 | // There are two solutions : two main branches of the hyperbola.+ | |
7fd59977 | 147 | //========================================================================= |
148 | ||
149 | else { | |
150 | // Standard_Real d1 = sqrt(dist*R1-R1*R1); | |
151 | Standard_Real d1 = sqrt(dist*dist-R1*R1)/2.0; | |
152 | Standard_Real d2 = R1/2.; | |
153 | if (Index == 1) { | |
154 | gp_Hypr2d biscirpnt1(majax,d2,d1); | |
155 | bissol = new GccInt_BHyper(biscirpnt1); | |
156 | // ========================================= | |
157 | } | |
158 | else { | |
159 | gp_Hypr2d biscirpnt1(majax,d2,d1); | |
160 | gp_Hypr2d biscirpnt2 = biscirpnt1.OtherBranch(); | |
161 | bissol = new GccInt_BHyper(biscirpnt2); | |
162 | // ========================================= | |
163 | } | |
164 | } | |
165 | } | |
166 | return bissol; | |
167 | } | |
168 | ||
169 | ||
170 | //========================================================================= | |
171 | ||
172 | Standard_Boolean GccAna_CircPnt2dBisec:: | |
173 | IsDone () const { return WellDone; } | |
174 | ||
175 | Standard_Integer GccAna_CircPnt2dBisec:: | |
176 | NbSolutions () const { return NbrSol; } | |
177 | ||
178 |