summaryrefslogtreecommitdiff
path: root/src/IntAna/IntAna_Quadric.cxx
blob: 27f15c0555c8ea595c33a252f5a4914278f67ac0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
// File:	IntAna_Quadric.cxx
// Created:	Wed Jul  1 11:37:37 1992
// Author:	Laurent BUCHARD
//		<lbr@topsn3>
#ifndef DEB
#define No_Standard_RangeError
#define No_Standard_OutOfRange
#endif

#include <IntAna_Quadric.ixx>
#include <gp_Trsf.hxx>
#include <gp_Vec.hxx>

//----------------------------------------------------------------------
//-- 
//--  Equation generale des quadriques :  
//-- 
//--   f(x,y,z) =       CXX X**2  + CYY Y**2  + CZZ Z**2
//--              
//--             + 2 (  CXY X Y   + CXZ X Z   + CYZ Y Z )
//-- 
//--             + 2 (  CX  X     + CY  Y     + CZ  Z)
//-- 
//--             + CCte
//-- 
//-- 
//----------------------------------------------------------------------





//----------------------------------------------------------------------
//-- Quadric Vide
//----------------------------------------------------------------------
IntAna_Quadric::IntAna_Quadric(void) {
  CXX=CYY=CZZ=CXY=CXZ=CYZ=CX=CY=CZ=0.0;   CCte=1.0;
}
//----------------------------------------------------------------------
//-- Pln  -----> Quadric
//-- 
//-- Coefficients sur gp_Pln retourne A,B,C,D 
//-- 	          avec f(x,y,z)  =    A x    + B y   +  C z   + D 
//-- 
//--  que l on identifie a        2(  CX x   + CY y  +  CZ z ) + CCte
//----------------------------------------------------------------------
void IntAna_Quadric::SetQuadric(const gp_Pln& P) {
  P.Coefficients(CX,CY,CZ,CCte);
  CX*=0.5; 
  CY*=0.5;
  CZ*=0.5;
  CXX=CYY=CZZ=CXY=CXZ=CYZ=0.0;
}

IntAna_Quadric::IntAna_Quadric(const gp_Pln& P) {
  P.Coefficients(CX,CY,CZ,CCte);  
  CX*=0.5; 
  CY*=0.5;
  CZ*=0.5;
  CXX=CYY=CZZ=CXY=CXZ=CYZ=0.0;
}
//----------------------------------------------------------------------
//-- Cylinder -----> Quadric
//----------------------------------------------------------------------
void IntAna_Quadric::SetQuadric(const gp_Cylinder& Cyl) {
  Cyl.Coefficients(CXX,CYY,CZZ,CXY,CXZ,CYZ,CX,CY,CZ,CCte);  
}

IntAna_Quadric::IntAna_Quadric(const gp_Cylinder& Cyl) {
  Cyl.Coefficients(CXX,CYY,CZZ,CXY,CXZ,CYZ,CX,CY,CZ,CCte);  
}
//----------------------------------------------------------------------
//-- Cone -----> Quadric
//----------------------------------------------------------------------
IntAna_Quadric::IntAna_Quadric(const gp_Cone& Cone) {
  Cone.Coefficients(CXX,CYY,CZZ,CXY,CXZ,CYZ,CX,CY,CZ,CCte);  
}

void IntAna_Quadric::SetQuadric(const gp_Cone& Cone) {
  Cone.Coefficients(CXX,CYY,CZZ,CXY,CXZ,CYZ,CX,CY,CZ,CCte);  
}
//----------------------------------------------------------------------
//-- Sphere -----> Quadric
//----------------------------------------------------------------------
void IntAna_Quadric::SetQuadric(const gp_Sphere& Sph) {
  Sph.Coefficients(CXX,CYY,CZZ,CXY,CXZ,CYZ,CX,CY,CZ,CCte);
}

IntAna_Quadric::IntAna_Quadric(const gp_Sphere& Sph) {
  Sph.Coefficients(CXX,CYY,CZZ,CXY,CXZ,CYZ,CX,CY,CZ,CCte);
}
//----------------------------------------------------------------------
//-- Returns the Coefficients of the Quadric
//----------------------------------------------------------------------
void IntAna_Quadric::Coefficients(Standard_Real& _CXX,Standard_Real& _CYY,Standard_Real& _CZZ,
				  Standard_Real& _CXY,Standard_Real& _CXZ,Standard_Real& _CYZ,
				  Standard_Real& _CX, Standard_Real& _CY, Standard_Real& _CZ,
				  Standard_Real& _CCte) const 
{
  _CXX=CXX; _CYY=CYY; _CZZ=CZZ;
  _CXY=CXY; _CXZ=CXZ; _CYZ=CYZ;
  _CX=CX;   _CY=CY;   _CZ=CZ;
  _CCte=CCte;
}
//----------------------------------------------------------------------
//-- Computes the Coefficients in a new coordinate system
//----------------------------------------------------------------------
void IntAna_Quadric::NewCoefficients( Standard_Real& _CXX,Standard_Real& _CYY,Standard_Real& _CZZ
				     ,Standard_Real& _CXY,Standard_Real& _CXZ,Standard_Real& _CYZ
				     ,Standard_Real& _CX, Standard_Real& _CY, Standard_Real& _CZ
				     ,Standard_Real& _CCte
				     ,const gp_Ax3& Axis) const 
{
  Standard_Real t11,t12,t13,t14;                  // x = t11 X + t12 Y + t13 Z + t14
  Standard_Real t21,t22,t23,t24;                  // y = t21 X + t22 Y + t23 Z + t24
  Standard_Real t31,t32,t33,t34;                  // z = t31 X + t32 Y + t33 Z + t34
                                 
                                                  //   = X DirX + Y DirY + Z DirZ + Loc
  
  Standard_Real Cxx,Cyy,Czz,Cxy,Cxz,Cyz,Cx,Cy,Cz,Ccte;            


  Axis.XDirection();
  Axis.YDirection();
  Axis.Direction();
  
  gp_Trsf Trans;
  
  Trans.SetTransformation(Axis);
  Trans.Invert();
  t11=Trans.Value(1,1);  t12=Trans.Value(1,2); t13=Trans.Value(1,3); t14=Trans.Value(1,4);
  t21=Trans.Value(2,1);  t22=Trans.Value(2,2); t23=Trans.Value(2,3); t24=Trans.Value(2,4);
  t31=Trans.Value(3,1);  t32=Trans.Value(3,2); t33=Trans.Value(3,3); t34=Trans.Value(3,4);
  
  
  //      P0(x,y,z)=_CXX x x + _CYY y y + ... + _CCte =0  (x,y,z "absolute" coordinates)
  // and  P1(X(x,y,z),Y(x,y,z),Z(x,y,z))=P0(x,y,z)
  //
  // with P1(X,Y,Z)= Cxx X X + Cyy Y Y + Czz Z Z + 2 Cxy X Y ... + Ccte
  //               = _CXX  x x + _CYY  y y  +  ...  +  _CCte
  
  Standard_Real t11_P2=t11*t11;  Standard_Real t21_P2=t21*t21;  Standard_Real t31_P2=t31*t31;
  Standard_Real t12_P2=t12*t12;  Standard_Real t22_P2=t22*t22;  Standard_Real t32_P2=t32*t32;
  Standard_Real t13_P2=t13*t13;  Standard_Real t23_P2=t23*t23;  Standard_Real t33_P2=t33*t33;
  Standard_Real t14_P2=t14*t14;  Standard_Real t24_P2=t24*t24;  Standard_Real t34_P2=t34*t34;

  Ccte = ((_CCte) 
	  + t14_P2* (_CXX) 
	  + t24_P2* (_CYY) 
	  + t34_P2* (_CZZ)
	  + 2.0 * ( t14*( (_CX) 
			 +t24* (_CXY) 
			 +t34* (_CXZ))
		   +t24*( (_CY) 
			 +t34* (_CYZ))
		   +t34* (_CZ)));
  
  Cxx = (  t11_P2* (_CXX) 
	 + t21_P2* (_CYY)
	 + t31_P2* (_CZZ)
	 + 2.0*( t11*( t21* (_CXY) 
		      +t31* (_CXZ))
 		+t21*t31* (_CYZ)));
  
  Cyy = (t12_P2* (_CXX) 
	 + t22_P2* (_CYY) 
	 + t32_P2* (_CZZ)
	 + 2.0*( t12*( t22* (_CXY) 
		      +t32* (_CXZ))
		+t22*t32* (_CYZ)));

  Czz = (t13_P2* (_CXX) 
	 + t33_P2* (_CZZ)
	 + t23_P2* (_CYY) 
	 + 2.0*( t13*( t23* (_CXY) 
		      +t33* (_CXZ))
		+t23*t33* (_CYZ)));

  Cz = (t13* (_CX) 
	+ t13*( t14* (_CXX) 
	       + t24* (_CXY) 
	       + t34* (_CXZ))
	+ t14*( t23* (_CXY) 
	       +t33* (_CXZ))
	+ t23*( (_CY) 
	       +t24* (_CYY) 
	       +t34* (_CYZ))
	+ t33*( t24* (_CYZ) 
	       +(_CZ)  
	       + t34* (_CZZ)));

  Cx = (t11* ((_CX) 
	      +t14* (_CXX) 
	      +t24* (_CXY) 
	      +t34* (_CXZ))
	+ t14*( t21* (_CXY) 
	       +t31* (_CXZ))
	+ t21*( (_CY) 
	       +t24* (_CYY)
	       +t34* (_CYZ))
	+ t31*( t24* (_CYZ) 
	       +(_CZ)
	       +t34* (_CZZ)));

  Cxy = (t11*( t12* (_CXX) 
	      +t22* (_CXY) 
	      +t32* (_CXZ))
	 + t12*( t21* (_CXY) 
		+t31* (_CXZ))
	 + t21*( t22* (_CYY) 
		+t32* (_CYZ))
	 + t31*( t22* (_CYZ) 
		+t32* (_CZZ)));

  Cxz = (t11*( t13* (_CXX) 
	      +t23* (_CXY) 
	      +t33* (_CXZ))
	 + t13*( t21* (_CXY) 
		+t31* (_CXZ))
	 + t21*( t23* (_CYY) 
		+t33* (_CYZ))
	 + t31*( t23* (_CYZ) 
		+t33* (_CZZ)));

  Cy = (t12* ( (_CX) 
	      +t14* (_CXX) 
	      +t24* (_CXY) 
	      +t34* (_CXZ))
	+ t14*( t22* (_CXY) 
	       +t32* (_CXZ))
	+ t22*( (_CY) 
	       +t24* (_CYY) 
	       +t34* (_CYZ))
	+ t32*( (_CZ) 
	       + t24* (_CYZ) 
	       + t34* (_CZZ)));

  Cyz = (t12*( t13* (_CXX) 
	      +t23* (_CXY) 
	      +t33* (_CXZ))
	 + t13*( t22* (_CXY) 
		+t32* (_CXZ))
	 + t22*( t23* (_CYY) 
		+t33* (_CYZ))
	 + t32*( t23* (_CYZ) 
		+t33* (_CZZ)));
  

  _CXX=Cxx; _CYY=Cyy; _CZZ=Czz;   _CX=Cx;   _CY=Cy;   _CZ=Cz;
  _CXY=Cxy; _CXZ=Cxz; _CYZ=Cyz;  _CCte=Ccte; 


}