7fd59977 |
1 | #include <StdFail_NotDone.hxx> |
2 | #include <Standard_OutOfRange.hxx> |
3 | //============================================================================= |
4 | |
5 | Extrema_ExtPSOfRev::Extrema_ExtPSOfRev (const gp_Pnt& P, |
6 | const SurfaceOfRevolution& S, |
7 | const Standard_Real Tol, |
8 | const Standard_Integer NbV, const Standard_Real TolV) |
9 | /*----------------------------------------------------------------------------- |
10 | Fonction: |
11 | Recherche de toutes les distances extremales entre le point P et la surface |
12 | de revolution S. |
13 | |
14 | Methode: |
15 | Soit Pp la projection du point P dans le plan XOY de la surface S; |
16 | 2 cas sont consideres: |
17 | 1- distance(Pp,O) < Tol: |
18 | Il existe 0 ou une infinite de solutions; IsDone() = Standard_False; |
19 | 2- distance(Pp,O) > Tol: |
20 | Soit U1 = angle(OX,OPp) avec 0. < U1 < 2.*PI, |
21 | U2 = U1 + PI avec 0. < U2 < 2.*PI, |
22 | M1 le meridien S(U1), |
23 | M2 le meridien S(U2); |
24 | On recherche les distances minimales entre P et M1 et les distances |
25 | maximales entre P et M2. Soit {V1i,i=1,n} et {V2j, j=1,m} ces solutions; |
26 | alors les (U1,V1i) correspondent a des distances minimales |
27 | et les (U2,V2j) correspondent a des distances maximales. |
28 | -----------------------------------------------------------------------------*/ |
29 | { |
30 | myDone = Standard_False; |
31 | |
32 | // Projection de P dans le plan XOY de la surface de revolution ... |
33 | gp_Ax3 Pos = Tool::Position(S); |
34 | gp_Pnt O = Pos.Location(); |
35 | gp_Vec OZ (Pos.Direction()); |
36 | gp_Pnt Pp = P.Translated(OZ.Multiplied(-(gp_Vec(O,P).Dot(OZ)))); |
37 | gp_Vec OPp (O,Pp); |
38 | if (OPp.Magnitude() < Tol) { return; } |
39 | |
40 | Standard_Real U1 = gp_Vec(Pos.XDirection()).AngleWithRef(OPp,OZ); |
41 | Standard_Real U2 = U1 + PI; |
42 | if (U1 < 0.) { U1 += 2. * PI; } |
43 | Curve M1 = Tool::Meridian(S, U1); |
44 | Curve M2 = Tool::Meridian(S, U2); |
45 | TheExtPC ExtPM1 (P,M1,NbV,TolV,Tol); |
46 | TheExtPC ExtPM2 (P,M2,NbV,TolV,Tol); |
47 | if ((ExtPM1.IsDone()) && (ExtPM2.IsDone())) { |
48 | Standard_Integer NbExt1 = ExtPM1.NbExt(); |
49 | Standard_Integer NbExt2 = ExtPM2.NbExt(); |
50 | Extrema_POnCurv ExtPM; |
51 | for (Standard_Integer NoExt = 1; NoExt <= NbExt1; NoExt++) { |
52 | if (ExtPM1.IsMin(NoExt)) { |
53 | ExtPM = ExtPM1.Point(NoExt); |
54 | mySqDist.Append(ExtPM1.SquareDistance(NoExt)); |
55 | myPoint.Append(Extrema_POnSurf(U1,ExtPM.Parameter(),ExtPM.SquareDistance())); |
56 | } |
57 | } |
58 | for (NoExt = 1; NoExt <= NbExt2; NoExt++) { |
59 | if (!ExtPM2.IsMin(NoExt)) { |
60 | ExtPM = ExtPM2.Point(NoExt); |
61 | mySqDist.Append(ExtPM2.SquareDistance(NoExt)); |
62 | myPoint.Append(Extrema_POnSurf(U2,ExtPM.Parameter(),ExtPM.SquareDistance())); |
63 | } |
64 | } |
65 | myDone = Standard_True; |
66 | } |
67 | } |
68 | //============================================================================= |
69 | |
70 | Standard_Boolean Extrema_ExtPSOfRev::IsDone () const { return myDone; } |
71 | //============================================================================= |
72 | |
73 | Standard_Integer Extrema_ExtPSOfRev::NbExt () const |
74 | { |
75 | if (!IsDone()) { StdFail_NotDone::Raise(); } |
76 | return mySqDist.Length(); |
77 | } |
78 | //============================================================================= |
79 | |
80 | Standard_Real Extrema_ExtPSOfRev::SquareDistance (const Standard_Integer N) const |
81 | { |
82 | if (!IsDone()) { StdFail_NotDone::Raise(); } |
83 | return mySqDist.Value(N); |
84 | } |
85 | //============================================================================= |
86 | |
87 | Extrema_POnSurf Extrema_ExtPSOfRev::Point (const Standard_Integer N) const |
88 | { |
89 | if (!IsDone()) { StdFail_NotDone::Raise(); } |
90 | return myPoint.Value(N); |
91 | } |
92 | //============================================================================= |