0031668: Visualization - WebGL sample doesn't work on Emscripten 1.39
[occt.git] / src / BRepBlend / BRepBlend_CurvPointRadInv.cxx
1 // Created on: 1997-02-12
2 // Created by: Laurent BOURESCHE
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
18 #include <Adaptor3d_HCurve.hxx>
19 #include <BRepBlend_CurvPointRadInv.hxx>
20 #include <gp_Pnt.hxx>
21 #include <math_Matrix.hxx>
22
23 //=======================================================================
24 //function : BRepBlend_CurvPointRadInv
25 //purpose  : 
26 //=======================================================================
27 BRepBlend_CurvPointRadInv::BRepBlend_CurvPointRadInv
28 (const Handle(Adaptor3d_HCurve)& C1,
29  const Handle(Adaptor3d_HCurve)& C2) : curv1(C1), curv2(C2)
30 {
31 }
32
33 //=======================================================================
34 //function : Set
35 //purpose  : 
36 //=======================================================================
37
38 void BRepBlend_CurvPointRadInv::Set(const Standard_Integer Choix) 
39 {
40   choix = Choix;
41 }
42
43 //=======================================================================
44 //function : NbEquations
45 //purpose  : 
46 //=======================================================================
47
48 Standard_Integer BRepBlend_CurvPointRadInv::NbEquations() const
49 {
50   return 2;
51 }
52
53 //=======================================================================
54 //function : Value
55 //purpose  : 
56 //=======================================================================
57
58 Standard_Boolean BRepBlend_CurvPointRadInv::Value(const math_Vector& X,
59                                                   math_Vector& F) 
60 {
61   Standard_Real theD;
62   gp_Pnt ptcur1, ptcur2;
63   gp_Vec d1cur1, d1cur2;
64   gp_XYZ nplan;//, ref;
65   curv1->D1(X(1),ptcur1, d1cur1);
66   nplan = d1cur1.Normalized().XYZ();
67   theD = -(nplan.Dot(ptcur1.XYZ()));
68   curv2->D1(X(2), ptcur2,  d1cur2);
69   F(1) = nplan.Dot(point.XYZ()) + theD;
70   F(2) = nplan.Dot(ptcur2.XYZ()) + theD;
71   return Standard_True;
72 }
73
74 //=======================================================================
75 //function : Derivatives
76 //purpose  : 
77 //=======================================================================
78
79 Standard_Boolean BRepBlend_CurvPointRadInv::Derivatives(const math_Vector& X,
80                                                         math_Matrix& D) 
81 {
82   gp_Pnt ptcur1, ptcur2;
83   gp_Vec d1cur1,d2cur1, d1cur2, nplan, dnplan;
84   Standard_Real dtheD, normd1cur1, unsurnormd1cur1;
85
86   curv1->D2(X(1), ptcur1, d1cur1, d2cur1);
87
88   normd1cur1      = d1cur1.Magnitude();
89   unsurnormd1cur1 = 1. / normd1cur1;
90   nplan           = unsurnormd1cur1 * d1cur1;
91   dnplan.SetLinearForm(-nplan.Dot(d2cur1), nplan, d2cur1);
92   dnplan.Multiply(unsurnormd1cur1);
93   dtheD  = - nplan.XYZ().Dot(d1cur1.XYZ()) - dnplan.XYZ().Dot(ptcur1.XYZ());
94   D(1,1) = dnplan.XYZ().Dot(point.XYZ()) + dtheD;
95   D(1,2) = 0.;
96   curv2->D1(X(2), ptcur2, d1cur2);
97   D(2,1) = dnplan.XYZ().Dot(ptcur2.XYZ()) + dtheD;
98   D(2,2) = nplan.Dot(d1cur2);
99
100   return Standard_True;
101 }
102
103 //=======================================================================
104 //function : Values
105 //purpose  : 
106 //=======================================================================
107
108 Standard_Boolean BRepBlend_CurvPointRadInv::Values(const math_Vector& X,
109                                                    math_Vector& F,
110                                                    math_Matrix& D) 
111 {
112   Value(X, F);
113   Derivatives(X, D);
114
115   return Standard_True;
116 }
117
118 //=======================================================================
119 //function : Set
120 //purpose  : 
121 //=======================================================================
122
123 void BRepBlend_CurvPointRadInv::Set(const gp_Pnt& P) 
124 {
125   point = P;
126 }
127
128 //=======================================================================
129 //function : GetTolerance
130 //purpose  : 
131 //=======================================================================
132
133 void BRepBlend_CurvPointRadInv::GetTolerance(math_Vector& Tolerance,
134                                              const Standard_Real Tol) const
135 {
136   Tolerance(1) = curv1->Resolution(Tol);
137   Tolerance(2) = curv2->Resolution(Tol);
138 }
139
140 //=======================================================================
141 //function : GetBounds
142 //purpose  : 
143 //=======================================================================
144
145 void BRepBlend_CurvPointRadInv::GetBounds(math_Vector& InfBound,
146                                           math_Vector& SupBound) const
147 {
148   InfBound(1) = curv1->FirstParameter();
149   SupBound(1) = curv1->LastParameter();
150   InfBound(2) = curv2->FirstParameter();
151   SupBound(2) = curv2->LastParameter();
152
153 }
154
155 //=======================================================================
156 //function : IsSolution
157 //purpose  : 
158 //=======================================================================
159
160 Standard_Boolean BRepBlend_CurvPointRadInv::IsSolution(const math_Vector&  Sol,
161                                                        const Standard_Real Tol) 
162 {
163   math_Vector valsol(1, 2);
164   Value(Sol,valsol);
165   if (Abs(valsol(1)) <= Tol && 
166       Abs(valsol(2)) <= Tol  ) {
167     return Standard_True;
168   }
169   return Standard_False;
170 }
171
172
173