1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
4 // The content of this file is subject to the Open CASCADE Technology Public
5 // License Version 6.5 (the "License"). You may not use the content of this file
6 // except in compliance with the License. Please obtain a copy of the License
7 // at http://www.opencascade.org and read it completely before using this file.
9 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 // The Original Code and all software distributed under the License is
13 // distributed on an "AS IS" basis, without warranty of any kind, and the
14 // Initial Developer hereby disclaims all such warranties, including without
15 // limitation, any warranties of merchantability, fitness for a particular
16 // purpose or non-infringement. Please see the License for the specific terms
17 // and conditions governing the rights and limitations under the License.
19 #include <IntAna2d_Conic.ixx>
22 IntAna2d_Conic::IntAna2d_Conic (const gp_Lin2d& L) {
27 L.Coefficients(d,e,f);
31 IntAna2d_Conic::IntAna2d_Conic (const gp_Circ2d& C) {
33 C.Coefficients(a,b,c,d,e,f);
37 IntAna2d_Conic::IntAna2d_Conic (const gp_Elips2d& E) {
39 E.Coefficients(a,b,c,d,e,f);
43 IntAna2d_Conic::IntAna2d_Conic (const gp_Parab2d& P) {
44 P.Coefficients(a,b,c,d,e,f);
48 IntAna2d_Conic::IntAna2d_Conic (const gp_Hypr2d& H) {
49 H.Coefficients(a,b,c,d,e,f);
53 void IntAna2d_Conic::NewCoefficients(Standard_Real& A,Standard_Real& B,Standard_Real& C
54 ,Standard_Real& D,Standard_Real& E,Standard_Real& F
55 ,const gp_Ax2d& Dir1) const {
56 Standard_Real t11,t12,t13; // x = t11 X + t12 Y + t13
57 Standard_Real t21,t22,t23; // y = t21 X + t22 Y + t23
58 Standard_Real A1,B1,C1,D1,E1,F1;
60 // P0(x,y)=A x x + B y y + ... + F =0 (x,y "absolute" coordinates)
61 // and P1(X(x,y),Y(x,y))=P0(x,y)
62 // with P1(X,Y)= A1 X X + B1 Y Y + 2 C1 X Y + 2 D1 X + 2 E1 Y + F1
63 // = A x x + B y y + 2 C x y + 2 D x + 2 E y + f
65 Dir1.Direction().Coord(t11,t21);
66 Dir1.Location().Coord(t13,t23);
71 A1=(t11*(A*t11 + 2*C*t21) + B*t21*t21);
72 B1=(t12*(A*t12 + 2*C*t22) + B*t22*t22);
73 C1=(t12*(A*t11 + C*t21) + t22*(C*t11 + B*t21));
74 D1=(t11*(D + A*t13) + t21*(E + C*t13) + t23*(C*t11 + B*t21));
75 E1=(t12*(D + A*t13) + t22*(E + C*t13) + t23*(C*t12 + B*t22));
76 F1=F + t13*(2.0*D + A*t13) + t23*(2.0*E + 2.0*C*t13 + B*t23);
78 A=A1; B=B1; C=C1; D=D1; E=E1; F=F1;
82 Standard_Real IntAna2d_Conic::Value (const Standard_Real X, const Standard_Real Y) const {
83 Standard_Real _a,_b,_c,_d,_e,_f;
84 this->Coefficients(_a,_b,_c,_d,_e,_f);
85 return (_a*X*X + _b*Y*Y + 2.*_c*X*Y + 2.*_d*X + 2.*_e*Y +_f);
88 gp_XY IntAna2d_Conic::Grad (const Standard_Real X, const Standard_Real Y) const {
89 Standard_Real _a,_b,_c,_d,_e,_f;
90 this->Coefficients(_a,_b,_c,_d,_e,_f);
91 return gp_XY(2.*_a*X + 2.*_c*Y + 2.*_d, 2.*_b*Y + 2.*_c*X + 2.*_e);
94 void IntAna2d_Conic::ValAndGrad (const Standard_Real X, const Standard_Real Y,
95 Standard_Real& Val, gp_XY& Grd) const {
96 Standard_Real la,lb,lc,ld,le,lf;
97 this->Coefficients(la,lb,lc,ld,le,lf);
98 Grd.SetCoord(2.*la*X + 2.*lc*Y + 2.*ld, 2.*lb*Y + 2.*lc*X + 2.*le);
99 Val = la*X*X + lb*Y*Y + 2.*lc*X*Y + 2.*ld*X + 2.*le*Y +lf;
103 void IntAna2d_Conic::Coefficients(Standard_Real& A,Standard_Real& B,Standard_Real& C,
104 Standard_Real& D,Standard_Real& E,Standard_Real& F) const
106 A=a; B=b; C=c; D=d; E=e; F=f;