inlib
1.2.0
|
00001 // Copyright (C) 2010, Guy Barrand. All rights reserved. 00002 // See the file inlib.license for terms. 00003 00004 #ifndef inlib_a4d 00005 #define inlib_a4d 00006 00007 #include "a4" 00008 00009 namespace inlib { 00010 namespace a4d { 00011 00015 00016 /* 00017 typedef inlib::a4d::vec<double> vecd; 00018 typedef inlib::a4d::sqm<double> sqmd; 00019 00020 inline bool l2(const vecd& a_vec,const sqmd& a_metrix,double& a_l2) { 00021 a_l2 = 0; 00022 array<double> tmp; 00023 if(!contract(a_metric,0,a_vec,0,tmp)) return false; 00024 return tmp.contract(a_metric,a_l2); 00025 } 00026 00027 inline bool x0normalize(vecd& a_vec,const sqmd& a_metric) { 00028 // 1 = g00 * v0 * v0 + 2 * v0 * (g0i * vi) + gjk * vj * vk; 00029 // 0 = a * x * x + b * x + c; 00030 // 00031 00032 double a = a_metric.value00(); 00033 00034 double b = 0; 00035 b += a_metric.v01() * a_vec.v1(); 00036 b += a_metric.v02() * a_vec.v2(); 00037 b += a_metric.v03() * a_vec.v3(); 00038 b *= 2; 00039 00040 double c = 0; 00041 c += a_metric.v11() * a_vec.v1() * a_vec.v1(); 00042 c += a_metric.v12() * a_vec.v1() * a_vec.v2(); 00043 c += a_metric.v13() * a_vec.v1() * a_vec.v3(); 00044 00045 c += a_metric.v21() * a_vec.v2() * a_vec.v1(); 00046 c += a_metric.v22() * a_vec.v2() * a_vec.v2(); 00047 c += a_metric.v23() * a_vec.v2() * a_vec.v3(); 00048 00049 c += a_metric.v31() * a_vec.v3() * a_vec.v1(); 00050 c += a_metric.v32() * a_vec.v3() * a_vec.v2(); 00051 c += a_metric.v33() * a_vec.v3() * a_vec.v3(); 00052 c -= 1; 00053 00054 double xm,xp; 00055 int n = mmanip::solve_equation_2_degree(a,b,c,xm,xp); 00056 if(n==0) return false; 00057 00058 if(n==1) { 00059 a_vec.v0(xm); 00060 } else { 00061 a_vec.v0(xp); 00062 } 00063 00064 return true; 00065 } 00066 */ 00067 00068 // 1 0 0 0 00069 // 0 1 0 0 00070 // 0 0 1 0 00071 // 0 0 0 1 00072 class id : public a4::sqm<double> { 00073 public: 00074 id(){ 00075 v00(1); 00076 v11(1); 00077 v22(1); 00078 v33(1); 00079 } 00080 }; 00081 00082 // 1 0 0 0 00083 // 0 -1 0 0 00084 // 0 0 -1 0 00085 // 0 0 0 -1 00086 class eta : public a4::sqm<double> { 00087 public: 00088 eta(){ 00089 v00( 1); 00090 v11(-1); 00091 v22(-1); 00092 v33(-1); 00093 } 00094 }; 00095 00096 // 0 0 0 1 00097 // 0 0 -1 0 00098 // 0 1 0 0 00099 // -1 0 0 0 00100 class J : public a4::sqm<double> { 00101 public: 00102 J(){ 00103 v03( 1); 00104 v12(-1); 00105 v21( 1); 00106 v30(-1); 00107 } 00108 }; 00109 00110 // 0 -1 0 0 00111 // 1 0 0 0 00112 // 0 0 0 1 00113 // 0 0 -1 0 00114 class K : public a4::sqm<double> { 00115 public: 00116 K(){ 00117 v01(-1); 00118 v10( 1); 00119 v23( 1); 00120 v32(-1); 00121 } 00122 }; 00123 // 0 0 1 0 0 -1 0 0 1 0 0 0 00124 // 0 0 0 1 -1 0 0 0 0 -1 0 0 00125 // 1 0 0 0 0 0 0 1 0 0 -1 0 00126 // 0 1 0 0 0 0 1 0 0 0 0 1 00127 class T1 : public a4::sqm<double> { 00128 public: 00129 T1(){ 00130 v02(1); 00131 v13(1); 00132 v20(1); 00133 v31(1); 00134 } 00135 }; 00136 class T2 : public a4::sqm<double> { 00137 public: 00138 T2(){ 00139 v01(-1); 00140 v10(-1); 00141 v23( 1); 00142 v32( 1); 00143 } 00144 }; 00145 class T3 : public a4::sqm<double> { 00146 public: 00147 T3(){ 00148 v00( 1); 00149 v11(-1); 00150 v22(-1); 00151 v33( 1); 00152 } 00153 }; 00154 00155 // E1 E2 E3 00156 // 0 0 0 0 0 0 0 0 0 0 0 0 00157 // 0 0 0 0 0 0 0 -1 0 0 1 0 00158 // 0 0 0 1 0 0 0 0 0 -1 0 0 00159 // 0 0 -1 0 0 1 0 0 0 0 0 0 00160 00161 // E4 E5 E6 00162 // 0 0 0 1 0 0 1 0 0 1 0 0 00163 // 0 0 0 0 0 0 0 0 -1 0 0 0 00164 // 0 0 0 0 -1 0 0 0 0 0 0 0 00165 // -1 0 0 0 0 0 0 0 0 0 0 0 00166 class E1 : public a4::sqm<double> { 00167 public: 00168 E1(){ 00169 v23( 1); 00170 v32(-1); 00171 } 00172 }; 00173 class E2 : public a4::sqm<double> { 00174 public: 00175 E2(){ 00176 v13(-1); 00177 v31( 1); 00178 } 00179 }; 00180 class E3 : public a4::sqm<double> { 00181 public: 00182 E3(){ 00183 v12( 1); 00184 v21(-1); 00185 } 00186 }; 00187 class E4 : public a4::sqm<double> { 00188 public: 00189 E4(){ 00190 v03( 1); 00191 v30(-1); 00192 } 00193 }; 00194 class E5 : public a4::sqm<double> { 00195 public: 00196 E5(){ 00197 v02( 1); 00198 v20(-1); 00199 } 00200 }; 00201 class E6 : public a4::sqm<double> { 00202 public: 00203 E6(){ 00204 v01( 1); 00205 v10(-1); 00206 } 00207 }; 00208 00209 /* 00210 // E[1,2,3] and K[1,2,3] can be used 00211 // to represent an antisymmetric matrix 00212 // with two 3D vectors (V,W) : 00213 // 00214 // 0 W1 W2 W3 00215 // A(V,W) = -W1 0 V3 -V2 00216 // -W2 -V3 0 V1 00217 // -W3 V2 -V1 0 00218 // 00219 // A(V,W) = V[j]*E[j] + W[j]*K[j] 00220 // 00221 00222 //K1 is E6 00223 //K2 is E5 00224 //K3 is E4 00225 class K1 : public a4::sqm<double> { 00226 public: 00227 K1(){ 00228 v01( 1); 00229 v10(-1); 00230 } 00231 }; 00232 class K2 : public a4::sqm<double> { 00233 public: 00234 K2(){ 00235 v02( 1); 00236 v20(-1); 00237 } 00238 }; 00239 class K3 : public a4::sqm<double> { 00240 public: 00241 K3(){ 00242 v03( 1); 00243 v30(-1); 00244 } 00245 }; 00246 */ 00247 00248 // quaternion matrix : 00249 // q = a + b*i + c*j + d*k 00250 // matrix : 00251 // a -b -c -d 00252 // b a -d c 00253 // c d a -b 00254 // d -c b a 00255 00256 // = a I + A 00257 // with det(A) = (b**2+c**2+d**2)**2 00258 00259 }} 00260 00261 #endif