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)
100 ElSLib::ConeParameters(myCone.Position(), myCone.RefRadius(), myCone.SemiAngle(), L.Location(),
106 ElSLib::ConeD1(U, V, myCone.Position(), myCone.RefRadius(), myCone.SemiAngle(),
110 if(Dv.IsParallel(L.Direction(), Precision::Angular())) {
112 myType = GeomAbs_Line;
116 Standard_Real Signe = L.Direction().Dot(Dv);
117 Signe = (Signe > 0.) ? 1. : -1.;
118 gp_Dir2d D2d(0., Signe);
120 myLin = gp_Lin2d( P2d, D2d);
122 isDone = Standard_True;
128 //=======================================================================
131 //=======================================================================
133 void ProjLib_Cone::Project(const gp_Circ& C)
135 myType = GeomAbs_Line;
137 gp_Ax3 ConePos = myCone.Position();
138 gp_Ax3 CircPos = C.Position();
140 gp_Dir ZCone = ConePos.XDirection().Crossed(ConePos.YDirection());
141 gp_Dir ZCir = CircPos.XDirection().Crossed(CircPos.YDirection());
144 Standard_Real x = ConePos.XDirection().Dot(CircPos.XDirection());
145 Standard_Real y = ConePos.YDirection().Dot(CircPos.XDirection());
147 = gp_Vec(myCone.Location(),C.Location()).Dot(ConePos.Direction());
149 // pour trouver le point U V, on reprend le code de ElSLib
150 // sans appliquer la Trsf au point ( aller retour inutile).
151 if ( x == 0.0 && y == 0.0 ) {
154 else if ( -myCone.RefRadius() > z * Tan(myCone.SemiAngle())) {
160 if ( U < 0.) U += 2*M_PI;
162 V = z / Cos(myCone.SemiAngle());
164 gp_Pnt2d P2d1 (U, V);
166 if ( ZCone.Dot(ZCir) > 0.)
167 D2d.SetCoord(1., 0.);
169 D2d.SetCoord(-1., 0.);
171 myLin = gp_Lin2d(P2d1, D2d);
172 isDone = Standard_True;
175 void ProjLib_Cone::Project(const gp_Elips& E)
177 ProjLib_Projector::Project(E);
180 void ProjLib_Cone::Project(const gp_Parab& P)
182 ProjLib_Projector::Project(P);
185 void ProjLib_Cone::Project(const gp_Hypr& H)
187 ProjLib_Projector::Project(H);