Commit | Line | Data |
---|---|---|
7fd59977 | 1 | // File: GccAna_CircLin2dBisec.cxx |
2 | // Created: Fri Oct 11 08:19:14 1991 | |
3 | // Author: Remi GILET | |
4 | // <reg@topsn3> | |
5 | ||
6 | //========================================================================= | |
0d969553 | 7 | // CREATION of the BISSECTICE between a CIRCLE and a STRAIGHT LINE. + |
7fd59977 | 8 | //========================================================================= |
9 | ||
10 | #include <GccAna_CircLin2dBisec.ixx> | |
11 | ||
12 | #include <gp_XY.hxx> | |
13 | #include <gp_Dir2d.hxx> | |
14 | #include <gp_Ax2d.hxx> | |
15 | #include <GccInt_BParab.hxx> | |
16 | #include <GccInt_BLine.hxx> | |
17 | #include <Standard_OutOfRange.hxx> | |
18 | #include <StdFail_NotDone.hxx> | |
19 | #include <gp.hxx> | |
20 | ||
21 | //========================================================================= | |
22 | ||
23 | GccAna_CircLin2dBisec:: | |
24 | GccAna_CircLin2dBisec (const gp_Circ2d& Circle , | |
25 | const gp_Lin2d& Line ): | |
26 | ||
27 | circle(Circle), | |
28 | line(Line) | |
29 | { | |
30 | ||
31 | //========================================================================= | |
0d969553 Y |
32 | // Initialization of fields : + |
33 | // - circle + | |
34 | // - line (straight line.) + | |
35 | // - NbrSol (number of solution.) + | |
36 | // - WellDone (Booleen showing success or failure of algorithm). + | |
7fd59977 | 37 | //========================================================================= |
38 | ||
39 | NbrSol = 2; | |
40 | WellDone = Standard_True; | |
41 | } | |
42 | ||
43 | //========================================================================= | |
0d969553 Y |
44 | // Processing. + |
45 | // Return coordinates of origins of the straight line (xloc,yloc) and the + | |
46 | // circle (xcencir, ycencir). + | |
47 | // Also return the coordinates of the direction of the straight line (xdir, + | |
48 | // ydir) and the radius of circle R1. + | |
49 | // Check at which side of the straight line is found the center of the circle + | |
50 | // to orientate the parabola (sign). + | |
51 | // Create axis of each parabola (axeparab1, axeparb2), then + | |
52 | // two parabolas (biscirlin1, biscirlin1). + | |
7fd59977 | 53 | //========================================================================= |
54 | ||
55 | Handle(GccInt_Bisec) GccAna_CircLin2dBisec:: | |
56 | ThisSolution (const Standard_Integer Index) const | |
57 | { | |
58 | ||
59 | if (!WellDone) StdFail_NotDone::Raise(); | |
60 | ||
61 | if ((Index <=0) || (Index > NbrSol)) Standard_OutOfRange::Raise(); | |
62 | ||
63 | Handle(GccInt_Bisec) bissol; | |
64 | Standard_Real xdir = line.Direction().X(); | |
65 | Standard_Real ydir = line.Direction().Y(); | |
66 | Standard_Real xloc = line.Location().X(); | |
67 | Standard_Real yloc = line.Location().Y(); | |
68 | Standard_Real xcencir = circle.Location().X(); | |
69 | Standard_Real ycencir = circle.Location().Y(); | |
70 | Standard_Real R1 = circle.Radius(); | |
71 | Standard_Real dist = line.Distance(circle.Location()); | |
72 | if ((Abs(line.Distance(circle.Location())-circle.Radius()) | |
73 | <= gp::Resolution()) && (Index == 1)) { | |
74 | gp_Lin2d biscirlin1(circle.Location(),gp_Dir2d(-ydir,xdir)); | |
75 | bissol = new GccInt_BLine(biscirlin1); | |
76 | // ========================================================== | |
77 | } | |
78 | else { | |
79 | Standard_Integer signe; | |
80 | if ((-ydir*(xcencir-xloc)+xdir*(ycencir-yloc)) > 0.0) { | |
81 | signe = 1; | |
82 | } | |
83 | else { | |
84 | signe = -1; | |
85 | } | |
86 | gp_Ax2d axeparab1; | |
87 | // gp_Ax2d axeparab2; | |
88 | gp_Parab2d biscirlin; | |
89 | if (dist != R1) { | |
90 | if (Index == 1) { | |
91 | axeparab1=gp_Ax2d(gp_Pnt2d(gp_XY(xcencir+signe*ydir*(dist+R1)/2, | |
92 | ycencir-signe*xdir*(dist+R1)/2.)), | |
93 | gp_Dir2d(-signe*ydir,signe*xdir)); | |
94 | biscirlin = gp_Parab2d(axeparab1,(dist+R1)/2.0); | |
95 | } | |
96 | else { | |
97 | if (dist < R1) { | |
98 | axeparab1=gp_Ax2d(gp_Pnt2d(gp_XY(xcencir+signe*ydir*(dist-R1)/2, | |
99 | ycencir-signe*xdir*(dist-R1)/2.)), | |
100 | gp_Dir2d(signe*ydir,-signe*xdir)); | |
101 | } | |
102 | else { | |
103 | axeparab1=gp_Ax2d(gp_Pnt2d(gp_XY(xcencir+signe*ydir*(dist-R1)/2, | |
104 | ycencir-signe*xdir*(dist-R1)/2.)), | |
105 | gp_Dir2d(-signe*ydir,signe*xdir)); | |
106 | } | |
107 | biscirlin = gp_Parab2d(axeparab1,Abs(dist-R1)/2.0); | |
108 | } | |
109 | bissol = new GccInt_BParab(biscirlin); | |
110 | // ========================================================== | |
111 | } | |
112 | else { | |
113 | axeparab1 = gp_Ax2d(gp_Pnt2d(gp_XY(xcencir+signe*ydir*(dist+R1)/2., | |
114 | ycencir-signe*xdir*(dist+R1)/2.)), | |
115 | gp_Dir2d(signe*(-ydir),signe*xdir)); | |
116 | biscirlin = gp_Parab2d(axeparab1,R1); | |
117 | bissol = new GccInt_BParab(biscirlin); | |
118 | // ========================================================== | |
119 | } | |
120 | } | |
121 | ||
122 | return bissol; | |
123 | } | |
124 | ||
125 | //========================================================================= | |
126 | ||
127 | Standard_Boolean GccAna_CircLin2dBisec:: | |
128 | IsDone () const { return WellDone; } | |
129 | ||
130 | Standard_Integer GccAna_CircLin2dBisec:: | |
131 | NbSolutions () const { return NbrSol; } | |
132 | ||
133 |