Tetszőleges tengely körüli forgatás (elmélet + gyakorlat) |
Írta Kaproncai Tamás [tomcat@szif.hu] |
A dokumentum szöveges verziója: AROTATE.TXT
A probléma megoldása a klasszikus Rodrigues-képlet:
(U
vektor körül fi szöggel elforgatás transzformációs mátrixa)
Rot(U,fi)= Cos(fi)*I + (1-Cos(fi))[UoU] + Sin(fi)[Ux]
I az egységmátrix: [ 1 0 0 ]
[ 0 1 0 ]
[ 0 0 1 ]
[UoU] = U-nak önmagával vett diadikus szorzata
[axbx axby axbz]
( [AoB] = [aybx ayby aybz] , A=B=U )
[azbx azby azbz]
[Ux] = U-val való vektorszorzás transzformációs mátrixa
[ 0 -uz uy ]
( [Ux] = [ uz 0 -ux ] )
[ -uy ux 0 ]
Ezután pl. egy P(px,py,pz) pont fi-vel való elforgatottja U körül:
P'(px',py',pz') = Rot(U,fi) * P(px,py,pz)
Számoljuk ki a transzformációs mátrixot:
a = Cos(fi)
b = 1-Cos(fi)
c = Sin(fi)
[ 1 0 0 ] [ ux2 uxuy uxuz ] [ 0 -uz uy ]
Rot(U,fi) = a * [ 0 1 0 ] + b * [ uyux uy2 uyuz ] + c * [ uz 0 -ux ]
[ 0 0 1 ] [ uzux uzuy uz2 ] [ -uy ux 0 ]
Az eredmény:
[ a+b*ux2 b*uxuy-c*uz b*uxuz+c*uy ]
[ b*uyux+c*uz a+b*uy2 b*uyuz-c*ux ]
[ b*uzux-c*uy b*uzuy+c*ux a+b*uz2 ]
Ez azonos a FvDFH
könyv 227. oldalán található (5.97) képlettel:
[ ux2+Cosfi(1-ux2) uxuy(1-Cosfi)-uzSinfi uzux(1-Cosfi)+uySinfi ]
[ uxuy(1-Cosfi)+uzSinfi uy2+Cosfi(1-uy2) uyuz(1-Cosfi)-yxSinfi ]
[ uzux(1-Cosfi)-uySinfi uyuz(1-Cosfi)+yxSinfi uz2+Cosfi(1-uz2) ]
Itt a megírt rutin is NASM
szintaktikával:
%macro ARotM33 2
FSINCOS ;;Cos(fi) Sin(fi)
FLD1 ;;1 Cos(fi) Sin(fi)
FSUB ST0,ST1 ;;1-Cos(fi) Cos(fi) Sin(fi)
FLD QWORD [%2+z] ;;uz b a c
FMUL ST0,ST3 ;;c*uz b a c
FLD QWORD [%2+y] ;;uy c*uz b a c
FMUL QWORD [%2+x] ;;uxuy c*uz b a c
FMUL ST0,ST2 ;;b*uxuy c*uz b a c
FSUBRP ST1,ST0 ;;b*uxuy-c*uz b a c
FLD QWORD [%2+y] ;;uy b*uxuy-c*uz b a c
FMUL ST0,ST4 ;;c*uy b*uxuy-c*uz b a c
FLD QWORD [%2+z] ;;uz c*uy b*uxuy-c*uz b a c
FMUL QWORD [%2+x] ;;uxuz c*uy b*uxuy-c*uz b a c
FMUL ST0,ST3 ;;b*uxuz c*uy b*uxuy-c*uz b a c
FADDP ST1,ST0 ;;b*uxuz+c*uy b*uxuy-c*uz b a c
FLD QWORD [%2+x] ;;ux b*uxuz+c*uy b*uxuy-c*uz b a c
FMUL ST0,ST0 ;;ux2 b*uxuz+c*uy b*uxuy-c*uz b a c
FMUL ST0,ST3 ;;b*ux2 b*uxuz+c*uy b*uxuy-c*uz b a c
FADD ST0,ST4 ;;a+b*ux2 b*uxuz+c*uy b*uxuy-c*uz b a c
FXCH ST2 ;;b*uxuy-c*uz b*uxuz+c*uy a+b*ux2 b a c
FSTP QWORD [%1+M33.12];;b*uxuz+c*uy a+b*ux2 b a c
FSTP QWORD [%1+M33.13];;a+b*ux2 b a c
FSTP QWORD [%1+M33.11];;b a c
FLD QWORD [%2+z] ;;uz b a c
FMUL ST0,ST3 ;;c*uz b a c
FLD QWORD [%2+x] ;;ux c*uz b a c
FMUL QWORD [%2+y] ;;uyux c*uz b a c
FMUL ST0,ST2 ;;b*uyux c*uz b a c
FADDP ST1,ST0 ;;b*uyux+c*uz b a c
FLD QWORD [%2+x] ;;ux b*uyux+c*uz b a c
FMUL ST0,ST4 ;;c*ux b*uyux+c*uz b a c
FLD QWORD [%2+z] ;;uz c*ux b*uyux+c*uz b a c
FMUL QWORD [%2+y] ;;uyuz c*ux b*uyux+c*uz b a c
FMUL ST0,ST3 ;;b*uyuz c*ux b*uyux+c*uz b a c
FSUBRP ST1,ST0 ;;b*uyuz-c*ux b*uyux+c*uz b a c
FLD QWORD [%2+y] ;;uy b*uyuz-c*ux b*uyux+c*uz b a c
FMUL ST0,ST0 ;;uy2 b*uyuz-c*ux b*uyux+c*uz b a c
FMUL ST0,ST3 ;;b*uy2 b*uyuz-c*ux b*uyux+c*uz b a c
FADD ST0,ST4 ;;a+b*uy2 b*uyuz-c*ux b*uyux+c*uz b a c
FXCH ST2 ;;b*uyux+c*uz b*uyuz-c*ux a+b*uy2 b a c
FSTP QWORD [%1+M33.21];;b*uyuz-c*ux a+b*uy2 b a c
FSTP QWORD [%1+M33.23];;a+b*uy2 b a c
FSTP QWORD [%1+M33.22];;b a c
FLD QWORD [%2+y] ;;uy b a c
FMUL ST0,ST3 ;;c*uy b a c
FLD QWORD [%2+x] ;;ux c*uy b a c
FMUL QWORD [%2+z] ;;uzux c*uy b a c
FMUL ST0,ST2 ;;b*uzux c*uy b a c
FSUBRP ST1,ST0 ;;b*uzux-c*uy b a c
FLD QWORD [%2+x] ;;ux b*uzux-c*uy b a c
FMUL ST0,ST4 ;;c*ux b*uzux-c*uy b a c
FLD QWORD [%2+y] ;;uy c*ux b*uzux-c*uy b a c
FMUL QWORD [%2+z] ;;uzuy c*ux b*uzux-c*uy b a c
FMUL ST0,ST3 ;;b*uzuy c*ux b*uzux-c*uy b a c
FADDP ST1,ST0 ;;b*uzuy+c*ux b*uzux-c*uy b a c
FLD QWORD [%2+z] ;;uz b*uzuy+c*ux b*uzux-c*uy b a c
FMUL ST0,ST0 ;;uz2 b*uzuy+c*ux b*uzux-c*uy b a c
FMUL ST0,ST3 ;;b*uz2 b*uzuy+c*ux b*uzux-c*uy b a c
FADD ST0,ST4 ;;a+b*uz2 b*uzuy+c*ux b*uzux-c*uy b a c
FXCH ST2 ;;b*uzux-c*uy b*uzuy+c*ux a+b*uz2 b a c
FSTP QWORD [%1+M33.31];;b*uzuy+c*ux a+b*uz2 b a c
FSTP QWORD [%1+M33.32];;a+b*uz2 b a c
FSTP QWORD [%1+M33.33];;b a c
FCOMP ST0
FCOMPP
%endmacro
%macro ARotM33 3
FLD QWORD [%3] ;;fi
ARotM33 %1,%2
%endmacro