1 // Created on: 1993-08-24
2 // Created by: Bruno DUMORTIER
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
24 #include <ProjLib_Cone.ixx>
26 #include <Precision.hxx>
29 #include <gp_Trsf.hxx>
30 #include <gp_Vec2d.hxx>
33 //=======================================================================
34 //function : ProjLib_Cone
36 //=======================================================================
38 ProjLib_Cone::ProjLib_Cone()
43 //=======================================================================
44 //function : ProjLib_Cone
46 //=======================================================================
48 ProjLib_Cone::ProjLib_Cone(const gp_Cone& Co)
54 //=======================================================================
55 //function : ProjLib_Cone
57 //=======================================================================
59 ProjLib_Cone::ProjLib_Cone(const gp_Cone& Co, const gp_Lin& L)
66 //=======================================================================
67 //function : ProjLib_Cone
69 //=======================================================================
71 ProjLib_Cone::ProjLib_Cone(const gp_Cone& Co, const gp_Circ& C)
78 //=======================================================================
81 //=======================================================================
83 void ProjLib_Cone::Init(const gp_Cone& Co)
85 myType = GeomAbs_OtherCurve;
87 myIsPeriodic = Standard_False;
88 isDone = Standard_False;
92 //=======================================================================
93 //function : EvalPnt2d / EvalDir2d
94 //purpose : returns the Projected Pnt / Dir in the parametrization range
96 //=======================================================================
99 static gp_Pnt2d EvalPnt2d( const gp_Pnt& P, const gp_Cone& C)
101 gp_Vec OP( C.Location(),P);
102 Standard_Real X = OP.Dot(gp_Vec(C.Position().XDirection()));
103 Standard_Real Y = OP.Dot(gp_Vec(C.Position().YDirection()));
104 Standard_Real Z = OP.Dot(gp_Vec(C.Position().Direction()));
107 if ( Abs(X) > Precision::PConfusion() ||
108 Abs(Y) > Precision::PConfusion() ) {
115 V = Z / Cos(C.SemiAngle());
117 return gp_Pnt2d( U, Z);
121 //=======================================================================
124 //=======================================================================
126 void ProjLib_Cone::Project(const gp_Lin& L)
132 V = gp_Vec(myCone.Location(),L.Location())
133 .Dot(gp_Vec(myCone.Position().Direction()));
134 V /= Cos( myCone.SemiAngle());
137 gp_Ax3 CPos = myCone.Position();
138 gp_Dir ZCone = CPos.XDirection() ^ CPos.YDirection();
140 gp_Ax3 RightHanded(CPos.Location(), ZCone, CPos.XDirection());
142 T.SetTransformation(RightHanded);
144 gp_Dir D = L.Position().Direction();
147 if ( D.Z() < 0.) D.Reverse();
149 U = gp::DX().AngleWithRef( D, gp::DZ());
151 Standard_Integer a1 =
152 (ZCone.IsEqual(CPos.Direction(), Precision::Angular())) ? 1 : -1;
153 Standard_Integer a2 =
154 (myCone.SemiAngle() > 0) ? 1 : -1;
155 if ( ( a1 * a2) == -1) U -= M_PI;
157 if ( U < 0.) U += 2.*M_PI;
162 ElSLib::ConeD1(U, V, CPos, myCone.RefRadius(), myCone.SemiAngle(),
165 if(Vv.IsParallel(gp_Vec(L.Position().Direction()), Precision::Angular())) {
167 myType = GeomAbs_Line;
171 Standard_Real Signe = L.Direction().Dot(myCone.Position().Direction());
172 Signe = (Signe > 0.) ? 1. : -1.;
173 gp_Dir2d D2d(0., Signe);
175 myLin = gp_Lin2d( P2d, D2d);
177 isDone = Standard_True;
183 //=======================================================================
186 //=======================================================================
188 void ProjLib_Cone::Project(const gp_Circ& C)
190 myType = GeomAbs_Line;
192 gp_Ax3 ConePos = myCone.Position();
193 gp_Ax3 CircPos = C.Position();
195 gp_Dir ZCone = ConePos.XDirection().Crossed(ConePos.YDirection());
196 gp_Dir ZCir = CircPos.XDirection().Crossed(CircPos.YDirection());
199 Standard_Real x = ConePos.XDirection().Dot(CircPos.XDirection());
200 Standard_Real y = ConePos.YDirection().Dot(CircPos.XDirection());
202 = gp_Vec(myCone.Location(),C.Location()).Dot(ConePos.Direction());
204 // pour trouver le point U V, on reprend le code de ElSLib
205 // sans appliquer la Trsf au point ( aller retour inutile).
206 if ( x == 0.0 && y == 0.0 ) {
209 else if ( -myCone.RefRadius() > z * Tan(myCone.SemiAngle())) {
215 if ( U < 0.) U += 2*M_PI;
217 V = z / Cos(myCone.SemiAngle());
219 gp_Pnt2d P2d1 (U, V);
221 if ( ZCone.Dot(ZCir) > 0.)
222 D2d.SetCoord(1., 0.);
224 D2d.SetCoord(-1., 0.);
226 myLin = gp_Lin2d(P2d1, D2d);
227 isDone = Standard_True;
230 void ProjLib_Cone::Project(const gp_Elips& E)
232 ProjLib_Projector::Project(E);
235 void ProjLib_Cone::Project(const gp_Parab& P)
237 ProjLib_Projector::Project(P);
240 void ProjLib_Cone::Project(const gp_Hypr& H)
242 ProjLib_Projector::Project(H);