1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
(*
rotating the point (x,y,z)
about the line through (a,b,c) with direction vector u,v,w
(where u^2 + v^2 + w^2 = 1) by the angle Theta.
H:=u*x+v*y+w*z
f(x,y,z,a,b,c,u,v,w,Theta) =
[a.(v^2+w^2) - u.(bv+cw-H)].(1-cos(Theta)) + x.cos(Theta) + (-cv+bw-wy+vz).sin(Theta)
[b.(u^2+w^2) - v.(au+cw-H)].(1-cos(Theta)) + y.cos(Theta) + (-aw+cu-uz+wx).sin(Theta)
[c.(u^2+v^2) - w.(au+bv-H)].(1-cos(Theta)) + z.cos(Theta) + (-bu+av-vx+uy).sin(Theta)
*)
var HX : double;
function RT( X,Y,Z,
a,b,c,
u,v,w,
T : double;
n : integer
) : double;
begin
Result:=0;
case n of
1 :
Result:=
(a*(sqr(v)+sqr(w)) - u*(b*v+c*w-HX))*(1-cos(T))
+ x*cos(T)
+ (-c*v+b*w-w*y+v*z)*sin(T);
2 :
Result:=
(b*(sqr(u)+sqr(w)) - v*(a*u+c*w-HX))*(1-cos(T))
+ y*cos(T)
+ (-a*w+c*u-u*z+w*x)*sin(T);
3 :
Result:=
(c*(sqr(u)+sqr(v)) - w*(a*u+b*v-HX))*(1-cos(T))
+ z*cos(T)
+ (-b*u+a*v-v*x+u*y)*sin(T);
end;
end;
procedure Rotate( x,y,z, // point a déplacer
a,b,c, // 1 point de l'axe
U,V,W, // vecteur directeur de l'axe de norme 1
Theta : double; // rotation en radian
var x_destination,y_destination,z_destination // point image du point à déplacer
: double
);
begin
HX:=sqr(U) + sqr(V) + sqr(W); // norme^2 de [u,v,w]
if HX < 1e-100 then exit; // vecteur directeur proposé nul
HX:= 1/sqrt(HX); // 1/norme
U:= U*HX; V:=V*HX; W:=W*Hx; // normalisation du vecteur directeur
HX:= U * x +
V * y +
W * z; //coefficient utilisé dans RT
x_destination:= RT(x, y, z, a, b, c, U, V, W, Theta,1);
y_destination:= RT(x, y, z, a, b, c, U, V, W, Theta,2);
z_destination:= RT(x, y, z, a, b, c, U, V, W, Theta,3);
end; |
Partager