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.
22 #include <Standard_NotImplemented.hxx>
24 #include <ProjLib_Cylinder.ixx>
26 #include <Precision.hxx>
28 #include <gp_Trsf.hxx>
31 #include <gp_Vec2d.hxx>
33 //=======================================================================
34 //function : ProjLib_Cylinder
36 //=======================================================================
38 ProjLib_Cylinder::ProjLib_Cylinder()
43 //=======================================================================
44 //function : ProjLib_Cylinder
46 //=======================================================================
48 ProjLib_Cylinder::ProjLib_Cylinder(const gp_Cylinder& Cyl)
54 //=======================================================================
55 //function : ProjLib_Cylinder
57 //=======================================================================
59 ProjLib_Cylinder::ProjLib_Cylinder(const gp_Cylinder& Cyl, const gp_Lin& L)
66 //=======================================================================
67 //function : ProjLib_Cylinder
69 //=======================================================================
71 ProjLib_Cylinder::ProjLib_Cylinder(const gp_Cylinder& Cyl, const gp_Circ& C)
78 //=======================================================================
79 //function : ProjLib_Cylinder
81 //=======================================================================
83 ProjLib_Cylinder::ProjLib_Cylinder(const gp_Cylinder& Cyl, const gp_Elips& E)
90 //=======================================================================
93 //=======================================================================
95 void ProjLib_Cylinder::Init(const gp_Cylinder& Cyl)
97 myType = GeomAbs_OtherCurve;
99 myIsPeriodic = Standard_False;
100 isDone = Standard_False;
104 //=======================================================================
105 //function : EvalPnt2d / EvalDir2d
106 //purpose : returns the Projected Pnt / Dir in the parametrization range
108 //=======================================================================
110 static gp_Pnt2d EvalPnt2d( const gp_Pnt& P, const gp_Cylinder& Cy )
112 gp_Vec OP( Cy.Location(),P);
113 Standard_Real X = OP.Dot(gp_Vec(Cy.Position().XDirection()));
114 Standard_Real Y = OP.Dot(gp_Vec(Cy.Position().YDirection()));
115 Standard_Real Z = OP.Dot(gp_Vec(Cy.Position().Direction()));
118 if ( Abs(X) > Precision::PConfusion() ||
119 Abs(Y) > Precision::PConfusion() ) {
125 return gp_Pnt2d( U, Z);
130 //=======================================================================
133 //=======================================================================
135 void ProjLib_Cylinder::Project(const gp_Lin& L)
137 myType = GeomAbs_Line;
139 gp_Pnt2d P2d = EvalPnt2d(L.Location(),myCylinder);
141 P2d.SetX(P2d.X()+2*M_PI);
144 = L.Direction().Dot(myCylinder.Position().Direction());
145 Signe = (Signe > 0.) ? 1. : -1.;
146 gp_Dir2d D2d(0., Signe);
148 myLin = gp_Lin2d( P2d, D2d);
149 isDone = Standard_True;
153 //=======================================================================
156 //=======================================================================
158 void ProjLib_Cylinder::Project(const gp_Circ& C)
160 myType = GeomAbs_Line;
162 gp_Dir ZCyl = myCylinder.Position().XDirection().Crossed
163 (myCylinder.Position().YDirection());
164 gp_Dir ZCir = C.Position().XDirection().Crossed
165 (C.Position().YDirection());
167 Standard_Real U = myCylinder.Position().XDirection()
168 .AngleWithRef(C.Position().XDirection(), ZCyl);
170 gp_Vec OP( myCylinder.Location(),C.Location());
171 Standard_Real V = OP.Dot(gp_Vec(myCylinder.Position().Direction()));
174 gp_Pnt2d P2d1 (U, V);
176 if ( ZCyl.Dot(ZCir) > 0.)
177 D2d.SetCoord(1., 0.);
179 D2d.SetCoord(-1., 0.);
181 myLin = gp_Lin2d(P2d1, D2d);
182 isDone = Standard_True;
186 //=======================================================================
189 //=======================================================================
191 //void ProjLib_Cylinder::Project(const gp_Elips& E)
192 void ProjLib_Cylinder::Project(const gp_Elips& )
194 // Pour de vastes raisons de periodicite mal gerees,
195 // la projection d`une ellipse sur un cylindre sera passee aux approx.
200 void ProjLib_Cylinder::Project(const gp_Parab& P)
202 ProjLib_Projector::Project(P);
205 void ProjLib_Cylinder::Project(const gp_Hypr& H)
207 ProjLib_Projector::Project(H);