7fd59977 |
1 | // File: Extrema_GenLocateExtPC.gxx |
2 | // Created: Tue Jul 18 17:40:47 1995 |
3 | // Author: Modelistation |
4 | // <model@metrox> |
5 | |
6 | |
7 | #include <StdFail_NotDone.hxx> |
8 | #include <Standard_DomainError.hxx> |
9 | #include <math_FunctionRoot.hxx> |
10 | |
11 | //======================================================================= |
12 | //function : Extrema_GenLocateExtPC |
13 | //purpose : |
14 | //======================================================================= |
15 | |
16 | Extrema_GenLocateExtPC::Extrema_GenLocateExtPC() |
17 | { |
18 | myDone = Standard_False; |
19 | } |
20 | |
21 | |
22 | //======================================================================= |
23 | //function : Extrema_GenLocateExtPC |
24 | //purpose : |
25 | //======================================================================= |
26 | |
27 | Extrema_GenLocateExtPC::Extrema_GenLocateExtPC (const Pnt& P, |
28 | const Curve& C, |
29 | const Standard_Real U0, |
30 | const Standard_Real TolU) |
31 | { |
32 | Initialize(C, Tool::FirstParameter(C), Tool::LastParameter(C), TolU); |
33 | Perform(P, U0); |
34 | } |
35 | |
36 | |
37 | //======================================================================= |
38 | //function : Extrema_GenLocateExtPC |
39 | //purpose : |
40 | //======================================================================= |
41 | |
42 | Extrema_GenLocateExtPC::Extrema_GenLocateExtPC (const Pnt& P, |
43 | const Curve& C, |
44 | const Standard_Real U0, |
45 | const Standard_Real Umin, |
46 | const Standard_Real Usup, |
47 | const Standard_Real TolU) |
48 | { |
49 | Initialize(C, Umin, Usup, TolU); |
50 | Perform(P, U0); |
51 | } |
52 | |
53 | |
54 | //======================================================================= |
55 | //function : Initialize |
56 | //purpose : |
57 | //======================================================================= |
58 | |
59 | void Extrema_GenLocateExtPC::Initialize(const Curve& C, |
60 | const Standard_Real Umin, |
61 | const Standard_Real Usup, |
62 | const Standard_Real TolU) |
63 | { |
64 | myDone = Standard_False; |
65 | myF.Initialize(C); |
66 | myumin = Umin; |
67 | myusup = Usup; |
68 | mytolU = TolU; |
69 | } |
70 | |
71 | |
72 | //======================================================================= |
73 | //function : Perform |
74 | //purpose : |
75 | //======================================================================= |
76 | |
77 | void Extrema_GenLocateExtPC::Perform(const Pnt& P, |
78 | const Standard_Real U0) |
79 | |
80 | /*----------------------------------------------------------------------------- |
81 | Fonction: |
82 | Recherche de la valeur de parametre U telle que: |
83 | - dist(P,C(u)) passe par un extremum, |
84 | - U soit la solution la plus proche de U0. |
85 | |
86 | Methode: |
87 | Si U est solution, alors F(U)=(C(U)-P).C'(U) = 0. |
88 | Le probleme consiste a rechercher, dans l'intervalle de definition |
89 | de la courbe, la racine de F la plus proche de U0. |
90 | On utilise la classe math_FunctionRoot avec les arguments de |
91 | construction suivants: |
92 | - F: Extrema_FuncExtPC cree a partir de P et C, |
93 | - U0, |
94 | - TolU, |
95 | - Uinf: borne inferieure de l'intervalle de definition, |
96 | - Ulast: borne superieure de l'intervalle de definition, |
97 | - 100. . |
98 | -----------------------------------------------------------------------------*/ |
99 | { |
100 | myF.SetPoint(P); |
101 | math_FunctionRoot S (myF, U0, mytolU, myumin, myusup); |
102 | myDone = S.IsDone(); |
103 | if (myDone) { |
104 | Standard_Real uu, ff; |
105 | POnC PP = Point(); |
106 | uu = PP.Parameter(); |
107 | if(myF.Value(uu, ff)) { |
108 | if (Abs(ff) >= 1.e-07) myDone = Standard_False; |
109 | } |
110 | else myDone = Standard_False; |
111 | } |
112 | } |
113 | |
114 | //======================================================================= |
115 | //function : IsDone |
116 | //purpose : |
117 | //======================================================================= |
118 | |
119 | Standard_Boolean Extrema_GenLocateExtPC::IsDone () const |
120 | { |
121 | return myDone; |
122 | } |
123 | |
124 | |
125 | //======================================================================= |
126 | //function : Value |
127 | //purpose : |
128 | //======================================================================= |
129 | |
130 | Standard_Real Extrema_GenLocateExtPC::SquareDistance() const |
131 | { |
132 | if (!myDone) { StdFail_NotDone::Raise(); } |
133 | return myF.SquareDistance(1); |
134 | } |
135 | |
136 | |
137 | //======================================================================= |
138 | //function : IsMin |
139 | //purpose : |
140 | //======================================================================= |
141 | |
142 | Standard_Boolean Extrema_GenLocateExtPC::IsMin () const |
143 | { |
144 | if (!myDone) { StdFail_NotDone::Raise(); } |
145 | return myF.IsMin(1); |
146 | } |
147 | |
148 | |
149 | //======================================================================= |
150 | //function : Point |
151 | //purpose : |
152 | //======================================================================= |
153 | |
154 | POnC Extrema_GenLocateExtPC::Point () const |
155 | { |
156 | if (!myDone) { StdFail_NotDone::Raise(); } |
157 | return myF.Point(1); |
158 | } |
159 | |