Download Implementation of SceneServer - a 3D software
Transcript
38
Implementation
cos θ 0 sin θ
1 0
0
R x ( θ ) = 0 cos θ – sin θ R y ( θ ) =
0 1 0 Rz( θ) =
0 sin θ cos θ
– sin θ 0 cos θ
Rotation matrices
cos θ – sin θ 0
sin θ cos θ 0
0
0 1
(5)
Multiplying, setting R = [ r ij ] for 0 ≤ i ≤ 2 and 0 ≤ j ≤ 2 and using
the notation c i = cos ( θ i ) and s i = sin ( θ i ) for i = x, y, z , yields:
r 00
r 10
r 20
r 01
r 11
r 21
r 02
cycz
=
r 12
czsxsy + cxsz
r 22
– cxczsy + sxsz
–c y s z
sy
c x c z – s x s y s z –c y s x
czsx + cxsysz cxcy
At first we see that s y = r 02 , and therefore θ y = asin ( r 02 ) . If
θ y ∈ (– π ⁄ 2,π ⁄ 2) , then c y ≠ 0 and c y (s x,c x) = (– r 12,r 22) in which
case θ x = atan 2 (– r 12,r 22) . Similarly, θ z = atan 2 (– r 01,r 00) .
This will be true in our case since we will not have rotations of 90
degrees or more around neither the y-axis or the x-axis. If
θ y ∈ {π ⁄ 2, – π ⁄ 2} it can be shown that the factorization is not
unique.
Thus:
θ x = atan 2 (– r 12,r 22)
θ y = asin ( r 02 )
θ z = atan 2 (– r 01,r 00)
Euler angles
(6)
The main reason why we wanted to use Euler angles is that they are
easier for the user to work with when editing an object. The alternative would be to use quaternions [11], that are superior to both Euler
angles and matrices when it comes to rotations and orientations.
When using quaternions though, you work with one angle and one
rotational axis, instead of three angles.
To get the result more realistic, the user can also specify how much
the vehicle should sink into the ground.
The function we have implemented, using four points to calculate the
transform, could of course be more advanced to gain a higher accuracy, but it works fine for this application.