1 // Created on: 1993-08-24
2 // Created by: Bruno DUMORTIER
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
20 #include <gp_Circ.hxx>
21 #include <gp_Cone.hxx>
22 #include <gp_Elips.hxx>
23 #include <gp_Hypr.hxx>
25 #include <gp_Parab.hxx>
26 #include <gp_Trsf.hxx>
28 #include <gp_Vec2d.hxx>
29 #include <Precision.hxx>
30 #include <ProjLib_Cone.hxx>
31 #include <Standard_NoSuchObject.hxx>
33 //=======================================================================
34 //function : ProjLib_Cone
36 //=======================================================================
37 ProjLib_Cone::ProjLib_Cone()
42 //=======================================================================
43 //function : ProjLib_Cone
45 //=======================================================================
47 ProjLib_Cone::ProjLib_Cone(const gp_Cone& Co)
53 //=======================================================================
54 //function : ProjLib_Cone
56 //=======================================================================
58 ProjLib_Cone::ProjLib_Cone(const gp_Cone& Co, const gp_Lin& L)
65 //=======================================================================
66 //function : ProjLib_Cone
68 //=======================================================================
70 ProjLib_Cone::ProjLib_Cone(const gp_Cone& Co, const gp_Circ& C)
77 //=======================================================================
80 //=======================================================================
82 void ProjLib_Cone::Init(const gp_Cone& Co)
84 myType = GeomAbs_OtherCurve;
86 myIsPeriodic = Standard_False;
87 isDone = Standard_False;
90 //=======================================================================
93 //=======================================================================
95 void ProjLib_Cone::Project(const gp_Lin& L)
97 gp_Pnt aPnt = L.Location(), anApex = myCone.Apex();
99 Standard_Real aDeltaV = 0.0;
102 if (aPnt.IsEqual(anApex, Precision::Confusion()))
104 //Take another point in the line L, which does not coincide with the cone apex.
105 aPnt.Translate(L.Direction().XYZ());
106 aDeltaV = 1.0; // == ||L.Direction()|| == 1.0
109 ElSLib::ConeParameters(myCone.Position(), myCone.RefRadius(), myCone.SemiAngle(), aPnt,
115 ElSLib::ConeD1(U, V, myCone.Position(), myCone.RefRadius(), myCone.SemiAngle(),
119 if(Dv.IsParallel(L.Direction(), Precision::Angular()))
121 // L is parallel to U-isoline of the cone.
122 myType = GeomAbs_Line;
124 const Standard_Real aSign = Sign(1.0, L.Direction().Dot(Dv));
125 gp_Pnt2d P2d(U, V - aDeltaV*aSign);
126 gp_Dir2d D2d(0., aSign);
128 myLin = gp_Lin2d( P2d, D2d);
130 isDone = Standard_True;
135 //=======================================================================
138 //=======================================================================
140 void ProjLib_Cone::Project(const gp_Circ& C)
142 myType = GeomAbs_Line;
144 gp_Ax3 ConePos = myCone.Position();
145 gp_Ax3 CircPos = C.Position();
147 if (!ConePos.Direction().IsParallel(CircPos.Direction(), Precision::Angular())) {
148 isDone = Standard_False;
152 gp_Dir ZCone = ConePos.XDirection().Crossed(ConePos.YDirection());
153 gp_Dir ZCir = CircPos.XDirection().Crossed(CircPos.YDirection());
156 Standard_Real x = ConePos.XDirection().Dot(CircPos.XDirection());
157 Standard_Real y = ConePos.YDirection().Dot(CircPos.XDirection());
159 = gp_Vec(myCone.Location(),C.Location()).Dot(ConePos.Direction());
161 // pour trouver le point U V, on reprend le code de ElSLib
162 // sans appliquer la Trsf au point ( aller retour inutile).
163 if ( x == 0.0 && y == 0.0 ) {
166 else if ( -myCone.RefRadius() > z * Tan(myCone.SemiAngle())) {
172 if ( U < 0.) U += 2*M_PI;
174 V = z / Cos(myCone.SemiAngle());
176 gp_Pnt2d P2d1 (U, V);
178 if ( ZCone.Dot(ZCir) > 0.)
179 D2d.SetCoord(1., 0.);
181 D2d.SetCoord(-1., 0.);
183 myLin = gp_Lin2d(P2d1, D2d);
184 isDone = Standard_True;
187 void ProjLib_Cone::Project(const gp_Elips& E)
189 ProjLib_Projector::Project(E);
192 void ProjLib_Cone::Project(const gp_Parab& P)
194 ProjLib_Projector::Project(P);
197 void ProjLib_Cone::Project(const gp_Hypr& H)
199 ProjLib_Projector::Project(H);