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