7b0822b23e8e797d32e493b9acae8fd879c09e5e
[occt.git] / src / GC / GC_MakeTrimmedCone.cxx
1 // Created on: 1992-10-02
2 // Created by: Remi GILET
3 // Copyright (c) 1992-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
18 #include <Extrema_ExtPElC.hxx>
19 #include <GC_MakeConicalSurface.hxx>
20 #include <GC_MakeTrimmedCone.hxx>
21 #include <Geom_ConicalSurface.hxx>
22 #include <Geom_RectangularTrimmedSurface.hxx>
23 #include <gp_Dir.hxx>
24 #include <gp_Lin.hxx>
25 #include <gp_Pnt.hxx>
26 #include <StdFail_NotDone.hxx>
27
28 //=========================================================================
29 //   Creation of a cone by four points.                                +
30 //   First two give the axis.                                     +
31 //   The third gives the base radius.                              +
32 //   the third and the fourth demi-angle.                          +
33 //=========================================================================
34 GC_MakeTrimmedCone::GC_MakeTrimmedCone(const gp_Pnt& P1 ,
35                                          const gp_Pnt& P2 ,
36                                          const gp_Pnt& P3 ,
37                                          const gp_Pnt& P4 ) 
38 {
39   GC_MakeConicalSurface Cone(P1,P2,P3,P4);
40   TheError = Cone.Status();
41   if (TheError == gce_Done) {
42     gp_Dir D1(P2.XYZ()-P1.XYZ());
43     gp_Lin L1(P1,D1);
44     Extrema_ExtPElC ext1(P3,L1,1.0e-7,-2.0e+100,+2.0e+100);
45     Extrema_ExtPElC ext2(P4,L1,1.0e-7,-2.0e+100,+2.0e+100);
46     gp_Pnt P5 = ext1.Point(1).Value();
47     gp_Pnt P6 = ext2.Point(1).Value();
48     Standard_Real D = P6.Distance(P5)/cos((Cone.Value())->SemiAngle());
49     TheCone=new Geom_RectangularTrimmedSurface(Cone.Value(),0.,2.*M_PI,0.,D,Standard_True,Standard_True);
50   }
51 }
52
53 //=========================================================================
54 //=========================================================================
55
56 GC_MakeTrimmedCone::GC_MakeTrimmedCone(const gp_Pnt&       P1 ,
57                                          const gp_Pnt&       P2 ,
58                                          const Standard_Real R1 ,
59                                          const Standard_Real R2 ) 
60 {
61   GC_MakeConicalSurface Cone(P1,P2,R1,R2);
62   TheError = Cone.Status();
63   if (TheError == gce_Done) {
64     Standard_Real D = (P2.Distance(P1))/cos((Cone.Value())->SemiAngle());
65     TheCone=new Geom_RectangularTrimmedSurface(Cone.Value(),0.,2.*M_PI,0.,D,Standard_True,Standard_True);
66   }
67 }
68
69 //=======================================================================
70 //function : Value
71 //purpose  : 
72 //=======================================================================
73
74 const Handle(Geom_RectangularTrimmedSurface)& GC_MakeTrimmedCone::
75        Value() const
76
77   StdFail_NotDone_Raise_if(TheError != gce_Done,"");
78   return TheCone;
79 }