1 // Created on: 1992-07-01
2 // Created by: Laurent BUCHARD
3 // Copyright (c) 1992-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #define No_Standard_RangeError
19 #define No_Standard_OutOfRange
24 #include <gp_Cone.hxx>
25 #include <gp_Cylinder.hxx>
27 #include <gp_Sphere.hxx>
28 #include <gp_Trsf.hxx>
30 #include <IntAna_Quadric.hxx>
32 //----------------------------------------------------------------------
34 //-- Equation generale des quadriques :
36 //-- f(x,y,z) = CXX X**2 + CYY Y**2 + CZZ Z**2
38 //-- + 2 ( CXY X Y + CXZ X Z + CYZ Y Z )
40 //-- + 2 ( CX X + CY Y + CZ Z)
45 //----------------------------------------------------------------------
46 //----------------------------------------------------------------------
48 //----------------------------------------------------------------------
49 IntAna_Quadric::IntAna_Quadric(void) {
50 CXX=CYY=CZZ=CXY=CXZ=CYZ=CX=CY=CZ=0.0; CCte=1.0;
52 //----------------------------------------------------------------------
53 //-- Pln -----> Quadric
55 //-- Coefficients sur gp_Pln retourne A,B,C,D
56 //-- avec f(x,y,z) = A x + B y + C z + D
58 //-- que l on identifie a 2( CX x + CY y + CZ z ) + CCte
59 //----------------------------------------------------------------------
60 void IntAna_Quadric::SetQuadric(const gp_Pln& P) {
61 P.Coefficients(CX,CY,CZ,CCte);
65 CXX=CYY=CZZ=CXY=CXZ=CYZ=0.0;
68 IntAna_Quadric::IntAna_Quadric(const gp_Pln& P) {
69 P.Coefficients(CX,CY,CZ,CCte);
73 CXX=CYY=CZZ=CXY=CXZ=CYZ=0.0;
75 //----------------------------------------------------------------------
76 //-- Cylinder -----> Quadric
77 //----------------------------------------------------------------------
78 void IntAna_Quadric::SetQuadric(const gp_Cylinder& Cyl) {
79 Cyl.Coefficients(CXX,CYY,CZZ,CXY,CXZ,CYZ,CX,CY,CZ,CCte);
82 IntAna_Quadric::IntAna_Quadric(const gp_Cylinder& Cyl) {
83 Cyl.Coefficients(CXX,CYY,CZZ,CXY,CXZ,CYZ,CX,CY,CZ,CCte);
85 //----------------------------------------------------------------------
86 //-- Cone -----> Quadric
87 //----------------------------------------------------------------------
88 IntAna_Quadric::IntAna_Quadric(const gp_Cone& Cone) {
89 Cone.Coefficients(CXX,CYY,CZZ,CXY,CXZ,CYZ,CX,CY,CZ,CCte);
92 void IntAna_Quadric::SetQuadric(const gp_Cone& Cone) {
93 Cone.Coefficients(CXX,CYY,CZZ,CXY,CXZ,CYZ,CX,CY,CZ,CCte);
95 //----------------------------------------------------------------------
96 //-- Sphere -----> Quadric
97 //----------------------------------------------------------------------
98 void IntAna_Quadric::SetQuadric(const gp_Sphere& Sph) {
99 Sph.Coefficients(CXX,CYY,CZZ,CXY,CXZ,CYZ,CX,CY,CZ,CCte);
102 IntAna_Quadric::IntAna_Quadric(const gp_Sphere& Sph) {
103 Sph.Coefficients(CXX,CYY,CZZ,CXY,CXZ,CYZ,CX,CY,CZ,CCte);
105 //----------------------------------------------------------------------
106 //-- Returns the Coefficients of the Quadric
107 //----------------------------------------------------------------------
108 void IntAna_Quadric::Coefficients(Standard_Real& _CXX,Standard_Real& _CYY,Standard_Real& _CZZ,
109 Standard_Real& _CXY,Standard_Real& _CXZ,Standard_Real& _CYZ,
110 Standard_Real& _CX, Standard_Real& _CY, Standard_Real& _CZ,
111 Standard_Real& _CCte) const
113 _CXX=CXX; _CYY=CYY; _CZZ=CZZ;
114 _CXY=CXY; _CXZ=CXZ; _CYZ=CYZ;
115 _CX=CX; _CY=CY; _CZ=CZ;
118 //----------------------------------------------------------------------
119 //-- Computes the Coefficients in a new coordinate system
120 //----------------------------------------------------------------------
121 void IntAna_Quadric::NewCoefficients( Standard_Real& _CXX,Standard_Real& _CYY,Standard_Real& _CZZ
122 ,Standard_Real& _CXY,Standard_Real& _CXZ,Standard_Real& _CYZ
123 ,Standard_Real& _CX, Standard_Real& _CY, Standard_Real& _CZ
124 ,Standard_Real& _CCte
125 ,const gp_Ax3& Axis) const
127 Standard_Real t11,t12,t13,t14; // x = t11 X + t12 Y + t13 Z + t14
128 Standard_Real t21,t22,t23,t24; // y = t21 X + t22 Y + t23 Z + t24
129 Standard_Real t31,t32,t33,t34; // z = t31 X + t32 Y + t33 Z + t34
131 // = X DirX + Y DirY + Z DirZ + Loc
133 Standard_Real Cxx,Cyy,Czz,Cxy,Cxz,Cyz,Cx,Cy,Cz,Ccte;
136 Trans.SetTransformation(Axis);
138 t11=Trans.Value(1,1); t12=Trans.Value(1,2); t13=Trans.Value(1,3); t14=Trans.Value(1,4);
139 t21=Trans.Value(2,1); t22=Trans.Value(2,2); t23=Trans.Value(2,3); t24=Trans.Value(2,4);
140 t31=Trans.Value(3,1); t32=Trans.Value(3,2); t33=Trans.Value(3,3); t34=Trans.Value(3,4);
143 // P0(x,y,z)=_CXX x x + _CYY y y + ... + _CCte =0 (x,y,z "absolute" coordinates)
144 // and P1(X(x,y,z),Y(x,y,z),Z(x,y,z))=P0(x,y,z)
146 // with P1(X,Y,Z)= Cxx X X + Cyy Y Y + Czz Z Z + 2 Cxy X Y ... + Ccte
147 // = _CXX x x + _CYY y y + ... + _CCte
149 Standard_Real t11_P2=t11*t11; Standard_Real t21_P2=t21*t21; Standard_Real t31_P2=t31*t31;
150 Standard_Real t12_P2=t12*t12; Standard_Real t22_P2=t22*t22; Standard_Real t32_P2=t32*t32;
151 Standard_Real t13_P2=t13*t13; Standard_Real t23_P2=t23*t23; Standard_Real t33_P2=t33*t33;
152 Standard_Real t14_P2=t14*t14; Standard_Real t24_P2=t24*t24; Standard_Real t34_P2=t34*t34;
158 + 2.0 * ( t14*( (_CX)
165 Cxx = ( t11_P2* (_CXX)
168 + 2.0*( t11*( t21* (_CXY)
172 Cyy = (t12_P2* (_CXX)
175 + 2.0*( t12*( t22* (_CXY)
179 Czz = (t13_P2* (_CXX)
182 + 2.0*( t13*( t23* (_CXY)
212 Cxy = (t11*( t12* (_CXX)
222 Cxz = (t11*( t13* (_CXX)
245 Cyz = (t12*( t13* (_CXX)
256 _CXX=Cxx; _CYY=Cyy; _CZZ=Czz; _CX=Cx; _CY=Cy; _CZ=Cz;
257 _CXY=Cxy; _CXZ=Cxz; _CYZ=Cyz; _CCte=Ccte;