26 if (j == 0) {
return xx_; }
27 if (j == 1) {
return xy_; }
28 if (j == 2) {
return xz_; }
29 if (j == 3) {
return dx_; }
31 if (j == 0) {
return yx_; }
32 if (j == 1) {
return yy_; }
33 if (j == 2) {
return yz_; }
34 if (j == 3) {
return dy_; }
36 if (j == 0) {
return zx_; }
37 if (j == 1) {
return zy_; }
38 if (j == 2) {
return zz_; }
39 if (j == 3) {
return dz_; }
41 if (j == 0) {
return 0.0; }
42 if (j == 1) {
return 0.0; }
43 if (j == 2) {
return 0.0; }
44 if (j == 3) {
return 1.0; }
46 std::cerr <<
"Transform3D subscripting: bad indeces "
47 <<
"(" << i <<
"," << j <<
")" << std::endl;
82 x1 = (fr1 - fr0).unit();
83 y1 = (fr2 - fr0).unit();
84 x2 = (to1 - to0).unit();
85 y2 = (to2 - to0).unit();
93 if (std::abs(1.0-cos1) <= 0.000001 || std::abs(1.0-cos2) <= 0.000001) {
94 std::cerr <<
"Transform3D: zero angle between axes" << std::endl;
97 if (std::abs(cos1-cos2) > 0.000001) {
98 std::cerr <<
"Transform3D: angles between axes are not equal"
104 z1 = (x1.
cross(y1)).unit();
107 z2 = (x2.
cross(y2)).unit();
110 double detxx = (y1.y()*z1.
z() - z1.
y()*y1.z());
111 double detxy = -(y1.x()*z1.
z() - z1.
x()*y1.z());
112 double detxz = (y1.x()*z1.
y() - z1.
x()*y1.y());
113 double detyx = -(x1.
y()*z1.
z() - z1.
y()*x1.
z());
114 double detyy = (x1.
x()*z1.
z() - z1.
x()*x1.
z());
115 double detyz = -(x1.
x()*z1.
y() - z1.
x()*x1.
y());
116 double detzx = (x1.
y()*y1.z() - y1.y()*x1.
z());
117 double detzy = -(x1.
x()*y1.z() - y1.x()*x1.
z());
118 double detzz = (x1.
x()*y1.y() - y1.x()*x1.
y());
120 double txx = x2.
x()*detxx + y2.x()*detyx + z2.
x()*detzx;
121 double txy = x2.
x()*detxy + y2.x()*detyy + z2.
x()*detzy;
122 double txz = x2.
x()*detxz + y2.x()*detyz + z2.
x()*detzz;
123 double tyx = x2.
y()*detxx + y2.y()*detyx + z2.
y()*detzx;
124 double tyy = x2.
y()*detxy + y2.y()*detyy + z2.
y()*detzy;
125 double tyz = x2.
y()*detxz + y2.y()*detyz + z2.
y()*detzz;
126 double tzx = x2.
z()*detxx + y2.z()*detyx + z2.
z()*detzx;
127 double tzy = x2.
z()*detxy + y2.z()*detyy + z2.
z()*detzy;
128 double tzz = x2.
z()*detxz + y2.z()*detyz + z2.
z()*detzz;
132 double dx1 = fr0.
x(), dy1 = fr0.
y(), dz1 = fr0.
z();
133 double dx2 = to0.
x(), dy2 = to0.
y(), dz2 = to0.
z();
135 setTransform(txx, txy, txz, dx2-txx*dx1-txy*dy1-txz*dz1,
136 tyx, tyy, tyz, dy2-tyx*dx1-tyy*dy1-tyz*dz1,
137 tzx, tzy, tzz, dz2-tzx*dx1-tzy*dy1-tzz*dz1);
155 double det =
xx_*detxx -
xy_*detxy +
xz_*detxz;
157 std::cerr <<
"Transform3D::inverse error: zero determinant" << std::endl;
160 det = 1./det; detxx *= det; detxy *= det; detxz *= det;
168 (detxx, -detyx, detzx, -detxx*
dx_+detyx*
dy_-detzx*
dz_,
169 -detxy, detyy, -detzy, detxy*
dx_-detyy*
dy_+detzy*dz_,
170 detxz, -detyz, detzz, -detxz*
dx_+detyz*
dy_-detzz*dz_);
189 double sx = std::sqrt(xx_*xx_ + yx_*yx_ + zx_*zx_);
190 double sy = std::sqrt(xy_*xy_ + yy_*yy_ + zy_*zy_);
191 double sz = std::sqrt(xz_*xz_ + yz_*yz_ + zz_*zz_);
193 if (xx_*(yy_*zz_-yz_*zy_) -
194 xy_*(yx_*zz_-yz_*zx_) +
195 xz_*(yx_*zy_-yy_*zx_) < 0) sz = -sz;
196 scale.setTransform(sx,0,0,0, 0,sy,0,0, 0,0,sz,0);
197 rotation.setTransform(xx_/sx,xy_/sy,xz_/sz,0,
198 yx_/sx,yy_/sy,yz_/sz,0,
199 zx_/sx,zy_/sy,zz_/sz,0);
200 translation.setTransform(1,0,0,dx_, 0,1,0,dy_, 0,0,1,dz_);
206 return ( (std::abs(
xx_ - t.
xx_) <= tolerance) &&
207 (std::abs(
xy_ - t.
xy_) <= tolerance) &&
208 (std::abs(
xz_ - t.
xz_) <= tolerance) &&
209 (std::abs(
dx_ - t.
dx_) <= tolerance) &&
210 (std::abs(
yx_ - t.
yx_) <= tolerance) &&
211 (std::abs(
yy_ - t.
yy_) <= tolerance) &&
212 (std::abs(
yz_ - t.
yz_) <= tolerance) &&
213 (std::abs(
dy_ - t.
dy_) <= tolerance) &&
214 (std::abs(
zx_ - t.
zx_) <= tolerance) &&
215 (std::abs(
zy_ - t.
zy_) <= tolerance) &&
216 (std::abs(
zz_ - t.
zz_) <= tolerance) &&
217 (std::abs(
dz_ - t.
dz_) <= tolerance) );
223 return (
this == &t) ?
true :
246 double cx = p2.
x()-p1.
x(), cy = p2.
y()-p1.
y(), cz = p2.
z()-p1.
z();
247 double ll = std::sqrt(cx*cx + cy*cy + cz*cz);
249 std::cerr <<
"Rotate3D: zero axis" << std::endl;
251 double cosa = std::cos(a), sina = std::sin(a);
252 cx /= ll; cy /= ll; cz /= ll;
254 double txx = cosa + (1-cosa)*cx*cx;
255 double txy = (1-cosa)*cx*cy - sina*cz;
256 double txz = (1-cosa)*cx*cz + sina*cy;
258 double tyx = (1-cosa)*cy*cx + sina*cz;
259 double tyy = cosa + (1-cosa)*cy*cy;
260 double tyz = (1-cosa)*cy*cz - sina*cx;
262 double tzx = (1-cosa)*cz*cx - sina*cy;
263 double tzy = (1-cosa)*cz*cy + sina*cx;
264 double tzz = cosa + (1-cosa)*cz*cz;
266 double tdx = p1.
x(), tdy = p1.
y(), tdz = p1.
z();
268 setTransform(txx, txy, txz, tdx-txx*tdx-txy*tdy-txz*tdz,
269 tyx, tyy, tyz, tdy-tyx*tdx-tyy*tdy-tyz*tdz,
270 tzx, tzy, tzz, tdz-tzx*tdx-tzy*tdy-tzz*tdz);
286 double ll = a*a+b*b+c*c;
288 std::cerr <<
"Reflect3D: zero normal" << std::endl;
292 double aa = a*a*ll,
ab = a*b*ll, ac = a*c*ll, ad = a*d*ll,
293 bb = b*b*ll, bc = b*c*ll, bd = b*d*ll,
294 cc = c*c*ll,
cd = c*d*ll;
296 -ab-ab, aa-bb+cc, -bc-bc, -bd-bd,
297 -ac-ac, -bc-bc, aa+bb-cc, -cd-cd);
BasicVector3D< T > cross(const BasicVector3D< T > &v) const