1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
21 #include <gp_Torus.hxx>
22 #include <gp_Trsf.hxx>
24 #include <Standard_ConstructionError.hxx>
25 #include <Standard_DimensionError.hxx>
27 void gp_Torus::Coefficients (TColStd_Array1OfReal& theCoef) const
32 // X = (R + r*cos(V))*cos(U)
33 // Y = (R + r*cos(V))*sin(U)
37 // 4*R*R*(r*r - Z*Z) = (X*X + Y*Y + Z*Z - R*R - r*r)^2
40 // 2*((X*Y)^2+(X*Z)^2+(Y*Z)^2)-
41 // 2*(R^2+r^2)*(X^2+Y^2)+
42 // 2*(R^2-r^2)*Z^2+(R^2-r^2)^2 = 0.0
44 const Standard_Integer aLowIndex = theCoef.Lower();
45 Standard_DimensionError_Raise_if (theCoef.Length() < 35,
46 "gp_Torus::theCoefficients(): Dimension mismatch");
49 aTr.SetTransformation (pos);
50 const Standard_Real aT11 = aTr.Value (1, 1);
51 const Standard_Real aT12 = aTr.Value (1, 2);
52 const Standard_Real aT13 = aTr.Value (1, 3);
53 const Standard_Real aT14 = aTr.Value (1, 4);
54 const Standard_Real aT21 = aTr.Value (2, 1);
55 const Standard_Real aT22 = aTr.Value (2, 2);
56 const Standard_Real aT23 = aTr.Value (2, 3);
57 const Standard_Real aT24 = aTr.Value (2, 4);
58 const Standard_Real aT31 = aTr.Value (3, 1);
59 const Standard_Real aT32 = aTr.Value (3, 2);
60 const Standard_Real aT33 = aTr.Value (3, 3);
61 const Standard_Real aT34 = aTr.Value (3, 4);
63 const Standard_Real aTcol1sq = aT11*aT11 + aT21*aT21 + aT31*aT31;
64 const Standard_Real aTcol2sq = aT12*aT12 + aT22*aT22 + aT32*aT32;
65 const Standard_Real aTcol3sq = aT13*aT13 + aT23*aT23 + aT33*aT33;
66 const Standard_Real aTcol4sq = aT14*aT14 + aT24*aT24 + aT34*aT34;
67 const Standard_Real aTcol1Tcol2 = aT11*aT12 + aT21*aT22 + aT31*aT32;
68 const Standard_Real aTcol1Tcol3 = aT11*aT13 + aT21*aT23 + aT31*aT33;
69 const Standard_Real aTcol2Tcol3 = aT12*aT13 + aT22*aT23 + aT32*aT33;
70 const Standard_Real aTcol1Tcol4 = aT11*aT14 + aT21*aT24 + aT31*aT34;
71 const Standard_Real aTcol2Tcol4 = aT12*aT14 + aT22*aT24 + aT32*aT34;
72 const Standard_Real aTcol3Tcol4 = aT13*aT14 + aT23*aT24 + aT33*aT34;
74 const Standard_Real aSumRadius = (majorRadius*majorRadius +
75 minorRadius*minorRadius);
76 const Standard_Real aSubRadius = (majorRadius*majorRadius -
77 minorRadius*minorRadius);
81 Transpose([X Y Z 1]) = aTr*Transpose([X Y Z 1])
85 theCoef(aLowIndex) = aTcol1sq*aTcol1sq; //X^4
86 theCoef(aLowIndex+1) = aTcol2sq*aTcol2sq; //Y^4
87 theCoef(aLowIndex+2) = aTcol3sq*aTcol3sq; //Z^4
88 theCoef(aLowIndex+3) = 4.0*aTcol1sq*aTcol1Tcol2; //X^3*Y
89 theCoef(aLowIndex+4) = 4.0*aTcol1sq*aTcol1Tcol3; //X^3*Z
90 theCoef(aLowIndex+5) = 4.0*aTcol2sq*aTcol1Tcol2; //X*Y^3
91 theCoef(aLowIndex+6) = 4.0*aTcol2sq*aTcol2Tcol3; //Y^3*Z
92 theCoef(aLowIndex+7) = 4.0*aTcol3sq*aTcol1Tcol3; //X*Z^3
93 theCoef(aLowIndex+8) = 4.0*aTcol3sq*aTcol2Tcol3; //Y*Z^3
94 theCoef(aLowIndex+9) = 2.0*(aTcol1sq*aTcol2sq +
95 2.0*aTcol1Tcol2*aTcol1Tcol2); //X^2*Y^2
96 theCoef(aLowIndex+10) = 2.0*(aTcol1sq*aTcol3sq +
97 2.0*aTcol1Tcol3*aTcol1Tcol3); //X^2*Z^2
98 theCoef(aLowIndex+11) = 2.0*(aTcol2sq*aTcol3sq +
99 2.0*aTcol2Tcol3*aTcol2Tcol3); //Y^2*Z^2
100 theCoef(aLowIndex+12) = 4.0*(aTcol1sq*aTcol2Tcol3 +
101 2.0*aTcol1Tcol2*aTcol1Tcol3); //X^2*Y*Z
102 theCoef(aLowIndex+13) = 4.0*(aTcol2sq*aTcol1Tcol3 +
103 2.0*aTcol1Tcol2*aTcol2Tcol3); //X*Y^2*Z
104 theCoef(aLowIndex+14) = 4.0*(aTcol3sq*aTcol1Tcol2 +
105 2.0*aTcol1Tcol3*aTcol2Tcol3); //X*Y*Z^2
107 theCoef(aLowIndex+15) = 4.0*aTcol1sq*aTcol1Tcol4; //X^3
108 theCoef(aLowIndex+16) = 4.0*aTcol2sq*aTcol2Tcol4; //Y^3
109 theCoef(aLowIndex+17) = 4.0*aTcol3sq*aTcol3Tcol4; //Z^3
110 theCoef(aLowIndex+18) = 4.0*(aTcol1sq*aTcol2Tcol4 +
111 2.0*aTcol1Tcol4*aTcol1Tcol2); //X^2*Y
112 theCoef(aLowIndex+19) = 4.0*(aTcol1sq*aTcol3Tcol4 +
113 2.0*aTcol1Tcol4*aTcol1Tcol3); //X^2*Z
114 theCoef(aLowIndex+20) = 4.0*(aTcol2sq*aTcol1Tcol4 +
115 2.0*aTcol2Tcol4*aTcol1Tcol2); //X*Y^2
116 theCoef(aLowIndex+21) = 4.0*(aTcol2sq*aTcol3Tcol4 +
117 2.0*aTcol2Tcol4*aTcol2Tcol3); //Y^2*Z
118 theCoef(aLowIndex+22) = 4.0*(aTcol3sq*aTcol1Tcol4 +
119 2.0*aTcol3Tcol4*aTcol1Tcol3); //X*Z^2
120 theCoef(aLowIndex+23) = 4.0*(aTcol3sq*aTcol2Tcol4 +
121 2.0*aTcol3Tcol4*aTcol2Tcol3); //Y*Z^2
122 theCoef(aLowIndex+24) = 8.0*(aTcol1Tcol2*aTcol3Tcol4 +
123 aTcol2Tcol3*aTcol1Tcol4 +
124 aTcol2Tcol4*aTcol1Tcol3); //X*Y*Z
126 theCoef(aLowIndex+25) = 2.0*(aSubRadius*aT31*aT31 -
127 aSumRadius*(aT11*aT11 + aT21*aT21) +
129 2.0*aTcol1Tcol4*aTcol1Tcol4); //X^2
130 theCoef(aLowIndex+26) = 2.0*(aSubRadius*aT32*aT32 -
131 aSumRadius*(aT12*aT12 + aT22*aT22) +
133 2.0*aTcol2Tcol4*aTcol2Tcol4); //Y^2
134 theCoef(aLowIndex+27) = 2.0*(aSubRadius*aT33*aT33 -
135 aSumRadius*(aT13*aT13 + aT23*aT23) +
137 2.0*aTcol3Tcol4*aTcol3Tcol4); //Z^2
138 theCoef(aLowIndex+28) = 4.0*(aSubRadius*aT31*aT32 -
139 aSumRadius*(aT11*aT12 + aT21*aT22) +
140 aTcol4sq*aTcol1Tcol2 +
141 2.0*aTcol1Tcol4*aTcol2Tcol4); //X*Y
142 theCoef(aLowIndex+29) = 4.0*(aSubRadius*aT31*aT33 -
143 aSumRadius*(aT11*aT13 + aT21*aT23) +
144 aTcol4sq*aTcol1Tcol3 +
145 2.0*aTcol1Tcol4*aTcol3Tcol4); //X*Z
146 theCoef(aLowIndex+30) = 4.0*(aSubRadius*aT32*aT33 -
147 aSumRadius*(aT12*aT13 + aT22*aT23) +
148 aTcol4sq*aTcol2Tcol3 +
149 2.0*aTcol2Tcol4*aTcol3Tcol4); //Y*Z
151 theCoef(aLowIndex+31) = 4.0*(aTcol4sq*aTcol1Tcol4 +
152 aSubRadius*aT31*aT34 -
153 aSumRadius*(aT11*aT14 + aT21*aT24)); //X
154 theCoef(aLowIndex+32) = 4.0*(aTcol4sq*aTcol2Tcol4 +
155 aSubRadius*aT32*aT34 -
156 aSumRadius*(aT12*aT14 + aT22*aT24)); //Y
157 theCoef(aLowIndex+33) = 4.0*(aTcol4sq*aTcol3Tcol4 +
158 aSubRadius*aT33*aT34 -
159 aSumRadius*(aT13*aT14 + aT23*aT24)); //Z;
161 theCoef(aLowIndex+34) = 2.0*aSubRadius*aT34*aT34 -
162 2.0*aSumRadius*(aT14*aT14 + aT24*aT24) +
163 aTcol4sq*aTcol4sq + aSubRadius*aSubRadius;
166 void gp_Torus::Mirror (const gp_Pnt& P)
169 gp_Torus gp_Torus::Mirrored (const gp_Pnt& P) const
176 void gp_Torus::Mirror (const gp_Ax1& A1)
179 gp_Torus gp_Torus::Mirrored (const gp_Ax1& A1) const
186 void gp_Torus::Mirror (const gp_Ax2& A2)
189 gp_Torus gp_Torus::Mirrored (const gp_Ax2& A2) const