0027322: geom/revolution_00/A1: Incorrect pcurve creation
[occt.git] / src / ProjLib / ProjLib_Cone.cxx
CommitLineData
b311480e 1// Created on: 1993-08-24
2// Created by: Bruno DUMORTIER
3// Copyright (c) 1993-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
7fd59977 17
42cf5bc1 18#include <ElSLib.hxx>
7fd59977 19#include <gp.hxx>
42cf5bc1 20#include <gp_Circ.hxx>
21#include <gp_Cone.hxx>
22#include <gp_Elips.hxx>
23#include <gp_Hypr.hxx>
24#include <gp_Lin.hxx>
25#include <gp_Parab.hxx>
7fd59977 26#include <gp_Trsf.hxx>
42cf5bc1 27#include <gp_Vec.hxx>
7fd59977 28#include <gp_Vec2d.hxx>
42cf5bc1 29#include <Precision.hxx>
30#include <ProjLib_Cone.hxx>
31#include <Standard_NoSuchObject.hxx>
7fd59977 32
33//=======================================================================
34//function : ProjLib_Cone
35//purpose :
36//=======================================================================
7fd59977 37ProjLib_Cone::ProjLib_Cone()
38{
39}
40
41
42//=======================================================================
43//function : ProjLib_Cone
44//purpose :
45//=======================================================================
46
47ProjLib_Cone::ProjLib_Cone(const gp_Cone& Co)
48{
49 Init(Co);
50}
51
52
53//=======================================================================
54//function : ProjLib_Cone
55//purpose :
56//=======================================================================
57
58ProjLib_Cone::ProjLib_Cone(const gp_Cone& Co, const gp_Lin& L)
59{
60 Init(Co);
61 Project(L);
62}
63
64
65//=======================================================================
66//function : ProjLib_Cone
67//purpose :
68//=======================================================================
69
70ProjLib_Cone::ProjLib_Cone(const gp_Cone& Co, const gp_Circ& C)
71{
72 Init(Co);
73 Project(C);
74}
75
76
77//=======================================================================
78//function : Init
79//purpose :
80//=======================================================================
81
82void ProjLib_Cone::Init(const gp_Cone& Co)
83{
84 myType = GeomAbs_OtherCurve;
85 myCone = Co;
86 myIsPeriodic = Standard_False;
87 isDone = Standard_False;
88}
89
7fd59977 90//=======================================================================
91//function : Project
92//purpose :
93//=======================================================================
94
95void ProjLib_Cone::Project(const gp_Lin& L)
96{
97
98 Standard_Real U,V;
8f8398f6 99
100 ElSLib::ConeParameters(myCone.Position(), myCone.RefRadius(), myCone.SemiAngle(), L.Location(),
101 U, V);
102 //
7fd59977 103 gp_Pnt P;
104 gp_Vec Vu, Vv;
105
8f8398f6 106 ElSLib::ConeD1(U, V, myCone.Position(), myCone.RefRadius(), myCone.SemiAngle(),
7fd59977 107 P, Vu, Vv);
108
8f8398f6 109 gp_Dir Dv(Vv);
110 if(Dv.IsParallel(L.Direction(), Precision::Angular())) {
7fd59977 111
112 myType = GeomAbs_Line;
113
114 gp_Pnt2d P2d(U,V);
115
8f8398f6 116 Standard_Real Signe = L.Direction().Dot(Dv);
7fd59977 117 Signe = (Signe > 0.) ? 1. : -1.;
118 gp_Dir2d D2d(0., Signe);
119
120 myLin = gp_Lin2d( P2d, D2d);
121
122 isDone = Standard_True;
123 }
124
125}
126
127
128//=======================================================================
129//function : Project
130//purpose :
131//=======================================================================
132
133void ProjLib_Cone::Project(const gp_Circ& C)
134{
135 myType = GeomAbs_Line;
136
137 gp_Ax3 ConePos = myCone.Position();
138 gp_Ax3 CircPos = C.Position();
139
140 gp_Dir ZCone = ConePos.XDirection().Crossed(ConePos.YDirection());
141 gp_Dir ZCir = CircPos.XDirection().Crossed(CircPos.YDirection());
142
143 Standard_Real U, V;
144 Standard_Real x = ConePos.XDirection().Dot(CircPos.XDirection());
145 Standard_Real y = ConePos.YDirection().Dot(CircPos.XDirection());
146 Standard_Real z
147 = gp_Vec(myCone.Location(),C.Location()).Dot(ConePos.Direction());
148
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 ) {
152 U = 0.;
153 }
154 else if ( -myCone.RefRadius() > z * Tan(myCone.SemiAngle())) {
155 U = ATan2(-y, -x);
156 }
157 else {
158 U = ATan2( y, x);
159 }
c6541a0c 160 if ( U < 0.) U += 2*M_PI;
7fd59977 161
162 V = z / Cos(myCone.SemiAngle());
163
164 gp_Pnt2d P2d1 (U, V);
165 gp_Dir2d D2d;
166 if ( ZCone.Dot(ZCir) > 0.)
167 D2d.SetCoord(1., 0.);
168 else
169 D2d.SetCoord(-1., 0.);
170
171 myLin = gp_Lin2d(P2d1, D2d);
172 isDone = Standard_True;
173}
174
175void ProjLib_Cone::Project(const gp_Elips& E)
176{
177 ProjLib_Projector::Project(E);
178}
179
180void ProjLib_Cone::Project(const gp_Parab& P)
181{
182 ProjLib_Projector::Project(P);
183}
184
185void ProjLib_Cone::Project(const gp_Hypr& H)
186{
187 ProjLib_Projector::Project(H);
188}
189