Euler Rotation: Difference between revisions

From Graal Bible
m (The point.)
No edit summary
 
(16 intermediate revisions by 4 users not shown)
Line 1: Line 1:
[[Category:Scripting Reference]]
== Definitions ==
== Definitions ==
Euler - Pronounced Oiler; discovered that as 1 is continuously compounded, it reaches a number, ''e''. However, Euler roation is taking a 3-dimensional object and rotating the axes on which it lies, in effect rotating the object as well.
Euler - Pronounced Oiler; discovered that as 1 is continuously compounded, it reaches a number, ''e''. However, Euler rotation is taking a 3-dimensional axes set and rotating them about the z-axis followed by a forward or backward rotation to create a new axes set.
For objects that inherit the property 'eulerrotation', the format is supposedly "Δ''β'' Δ''α'' Δ''γ''". Read further for a better explanation.
For objects that inherit the property 'eulerrotation', the format is supposedly "Δ''α'' Δ''β'' Δ''γ''". Read further for a better explanation.




''&theta;'': greek letter ''theta''<br />
''&theta;'': greek letter ''theta''<br />
''&phi;'': greek letter ''phi''<br />
''&phi;'': greek letter ''phi''<br />
''theta'' and ''phi'' are most commonly used in trigonometry for angles.<br />
''theta'' and ''phi'' are commonly used in trigonometry for angles (but phi is most commonly used as a constant: 1.618...).<br />
''&alpha;'': 1<sup>st</sup> greek letter ''alpha''. For our purposes, it will represent rotation about the y-axis.<br />
''&alpha;'': 1<sup>st</sup> greek letter ''alpha''. For our purposes, it will represent The angle between the original x axis and the normal vector<sup>(1)</sup>.<br />
''&beta;'': 2<sup>nd</sup> greek letter ''beta''. For our purposes, it will represent rotation about the x-axis.<br />
''&beta;'': 2<sup>nd</sup> greek letter ''beta''. For our purposes, it will represent the forward or backward "tilt".<br />
''&gamma;'': 3<sup>rd</sup> greek letter ''gamma''. For our purposes, it will represent rotation about the z-axis.<br />
''&gamma;'': 3<sup>rd</sup> greek letter ''gamma''. For our purposes, it will represent the angle between the normal vector<sup>(1)</sup> and the new x axis.<br />


Therefore, images and text could be rotated, something that could not be done before, so that said image or text would have a three-dimensional effect. If all said is true, eulerrotation = "-pi/3 0 0"; for text would project it in a Star Wars-like fashion.
Therefore, images and text could be rotated, something that could not be done before, so that said image or text would have a three-dimensional effect. If all said is true, eulerrotation = "0 -pi/3 0"; for text would project it in a Star Wars-like fashion.


  sin(''&theta;'') = y / ''r'' (&Delta;y of a point from the center on a circle with radius ''r'')
  sin(''&theta;'') = y / ''r'' (&Delta;y of a point from the center on a circle with radius ''r'')
Line 23: Line 24:
  sec(''&theta;'') = 1 / cos(''&theta;'')
  sec(''&theta;'') = 1 / cos(''&theta;'')
  csc(''&theta;'') = 1 / sin(''&theta;'')
  csc(''&theta;'') = 1 / sin(''&theta;'')
== Deriving the 2D equations ==
Simply:<br />
x² + y² = ''r''²; the basic equation of a circle with center (0,0)
x² + y² + z² = ''r''²; the basic equation of a sphere with center (0,0,0)
sin²(''&theta;'') + cos²(''&theta;'') = 1
arctan(y/x) = ''&theta;''; arctan() being the inverse of tangent
tan(arctan(y/x)) = tan(''&theta;'')
y/x = tan(''&theta;'')
y/x = ''r'' sin(''&theta;'') / ''r'' cos(''&theta;'')
Thus,<br />
''r'' sin(''&theta;'') = y
''r'' cos(''&theta;'') = x
Likewise,
sin(''&theta;'') = y / ''r''
cos(''&theta;'') = x / ''r''
Plugging into the circle equation, we get
''r''² = ''r''² cos²(''&theta;'') + ''r''² sin²(''&theta;'')
Compare:
&radic;(a² + b²) = c (the distance formula)
x² + y² = ''r''² (established as the equation of a circle)
&radic;(a² + b²) = c
( &radic;(a² + b²) )² = c²
a² + b² = c²
== Rotation on a single plane ==
Think of a circle with some radius, ''r'', and a point somewhere on it. This circle is a two-dimensional figure on the xy [or y(x)] plane. The angle between 0º and the point is ''&theta;''. <br />
Trigonometric functions sine and cosine are specific to determine x and y values according the the angle passed as its parameter. <br />
To keep things simple, we will rotate about the (invisible) z-axis. In doing so, x and y are changing. Any z values that a point may have remain constant. ''&phi;'' is a second angle, representing the amount of rotation.<br />
y = ''r'' sin(''&theta;''), so,
y = ''r'' sin(''&theta;'' + ''&phi;'')
y = ''r'' ( sin(''&theta;'') cos(''&phi;'') + cos(''&theta;'') sin(''&phi;'') )
y = ''r'' sin(''&theta;'') cos(''&phi;'') + ''r'' cos(''&theta;'') sin(''&phi;'')
Using substitutions form above, we can simplify to<br />
y = y cos(''&phi;'') + x sin(''&phi;'')
Alternatively,<br />
x = ''r'' cos(''&theta;'')
x = ''r'' cos(''&theta;'' + ''&phi;'')
x = ''r'' ( cos(''&theta;'') cos(''&phi;'') - sin(''&theta;'') sin(''&phi;'') )
x = ''r'' cos(''&theta;'') cos(''&phi;'') - ''r'' sin(''&theta;'') sin(''&phi;'')
x = x cos(''&phi;'') - y sin(''&phi;'')
== Deriving the 3D equations ==
As above, we can change the sphere's equation into a series of distance formulas
x² + y² + z² = ''r''²
( &radic;(x² + y²) )² + z² = ''r''²
( &radic;( ( &radic;(x² + y²) )² + z² ) )² = ''r''²
&radic;( x² + y² + z² ) = ''r''
''r''&radic;( ( sin²(''&theta;'') + cos²(''&theta;'') ) sin²(''&phi;'') + cos²(''&phi;'') ) = ''r''
&radic;( ( &radic( sin²(''&theta;'') + cos²(''&theta;'') ) )² sin²(''&phi;'') + cos²(''&phi;'') ) = 1
( sin²(''&theta;'') + cos²(''&theta;'') )² sin²(''&phi;'') + cos²(''&phi;'') = 1
sin²(''&theta;'') sin²(''&phi;'') + cos²(''&theta;'') sin²(''&phi;'') + cos²(''&phi;'') = 1
Comparing with the original equation we can split it up and get individual equations for x,y, and z.
y = sin(''&theta;'') sin(''&phi;'') <sup>(1)</sup>
x = cos(''&theta;'') sin(''&phi;'') <sup>(1)</sup>
z = cos(''&phi;'')
The equation is
( sin²(''&theta;'') + cos²(''&theta;'') ) ( sin²(''&phi;'') + cos²(''&phi;'') ) = 1
So, why doesn't the ( sin²(''&theta;'') + cos²(''&theta;'') ) distribute to the cos²(''&phi;'')? If you'll recall, ( sin²(''&theta;'') + cos²(''&theta;'') ) = 1, so it ''could be'' that it was. But also, it was left out so that there were only 3 terms as opposed to 4 (We only want three: x, y, and z!).


<hr width="33%" NOSHADE>
<hr width="33%" NOSHADE>
<sup>(1)</sup> The portion used contained the original x or y equation, so was split up to match, but it doesn't matter in the end.
<sup>(1)</sup> The normal vector is the vector perpendicular to the original z and the new z axes. This can be calculated through [[Cross Product|cross product]].
 
 
== Rotation on three planes ==
 
Now in three dimensions:<br />
Imagine three planes that intersect: xy [y(x)], yz [z(y)], zx [x(z)] (using these names helps remember the order of calculations if re-writing the script... you'll see). <br />
For this, instead of merely one rotation angle, we will need three (''&alpha;'', ''&beta;'', and ''&gamma;''). Also, we will need to replace the simple x and y with their three-dimensional counterparts and add a z (To begin, ''f'' = ''f''<sub>0</sub>).<br />
x<sub>0</sub> = ''r'' sin(''&alpha;'') cos(''&beta;'')
y<sub>0</sub> = ''r'' sin(''&alpha;'') sin(''&beta;'')
z<sub>0</sub> = ''r'' cos(''&alpha;'')
 
About the x-axis:<br />
Finally, rotate our three planes to replace z with x, y with z, and x with y.<br />
nz = z cos(''&beta;'') + y sin(''&beta;'')
ny = y cos(''&beta;'') - z sin(''&beta;'')
Note how as the axes are switched, the x, y, and z or replaced respectively from the 2D rotation equations!
 
We then replace y with ny and z with nz. So in a sense,<br />
z = nz
y = ny
 
About the y-axis:<br />
Now imagine the 3 planes rotate forward 90º and 90º to the left. The z has taken the place of the x, x in the stead of y, and y in that of z. The idea of this rotation is now just like that above, but y is constant.<br />
nx = x cos(''&alpha;'') + z sin(''&alpha;'')
nz = z cos(''&alpha;'') - x sin(''&alpha;'')
 
x = nx
 
The two-dimensions calculations work for rotations about the z-axis.<br />
About the z-axis:<br />
ny = y cos(''&gamma;'') + x sin(''&gamma;'')
nx = x cos(''&gamma;'') - y sin(''&gamma;'')
 
We expand to simplify:<br />
 
x = x cos(''&gamma;'') - y sin(''&gamma;'')
x = ( x<sub>0</sub> cos(''&alpha;'') + ( z<sub>0</sub> cos(''&beta;'') + y<sub>0</sub> sin(''&beta;'') ) sin(''&alpha;'') ) cos(''&gamma;'') - ( y<sub>0</sub> cos(''&beta;'') - z<sub>0</sub> sin(''&beta;'') ) sin(''&gamma;'')
x = x<sub>0</sub> cos(''&alpha;'') cos(''&gamma;'') + z<sub>0</sub> cos(''&beta;'') sin(''&alpha;'') cos(''&gamma;'') + y<sub>0</sub> sin(''&beta;'') sin(''&alpha;'') cos(''&gamma;'') - y<sub>0</sub> cos(''&beta;'') sin(''&gamma;'') + z<sub>0</sub> sin(''&beta;'') sin(''&gamma;'')
x = x<sub>0</sub> cos(''&alpha;'') cos(''&gamma;'') + y<sub>0</sub> ( sin(''&beta;'') sin(''&alpha;'') cos(''&gamma;'') - cos(''&beta;'') sin(''&gamma;'') ) + z<sub>0</sub> ( cos(''&beta;'') sin(''&alpha;'') cos(''&gamma;'') + sin(''&beta;'') sin(''&gamma;'') )
 
y = y cos(''&gamma;'') + x sin(''&gamma;'')
y = ( y<sub>0</sub> cos(''&beta;'') - z<sub>0</sub> sin(''&beta;'') ) cos(''&gamma;'') +  ( x<sub>0</sub> cos(''&alpha;'') + ( z<sub>0</sub> cos(''&beta;'') + y<sub>0</sub> sin(''&beta;'') ) sin(''&alpha;'') ) sin(''&gamma;'')
y = y<sub>0</sub> cos(''&beta;'') cos(''&gamma;'') - z<sub>0</sub> sin(''&beta;'') cos(''&gamma;'') + x<sub>0</sub> cos(''&alpha;'') sin(''&gamma;'') + z<sub>0</sub> cos(''&beta;'') sin(''&alpha;'') sin(''&gamma;'') + y<sub>0</sub> sin(''&beta;'') sin(''&alpha;'') sin(''&gamma;'')
y = x<sub>0</sub> cos(''&alpha;'') sin(''&gamma;'') + y<sub>0</sub> ( cos(''&beta;'') cos(''&gamma;'') + sin(''&beta;'') sin(''&alpha;'') sin(''&gamma;'') ) + z<sub>0</sub> ( -sin(''&beta;'') cos(''&gamma;'') + cos(''&beta;'') sin(''&alpha;'') sin(''&gamma;'') )
 
z = z cos(''&alpha;'') - x sin(''&alpha;'')
z = ( z<sub>0</sub> cos(''&beta;'') + y<sub>0</sub> sin(''&beta;'') ) cos(''&alpha;'') - x<sub>0</sub> sin(''&alpha;'')
z = z<sub>0</sub> cos(''&beta;'') cos(''&alpha;'') + y<sub>0</sub> sin(''&beta;'') cos(''&alpha;'') - x<sub>0</sub> sin(''&alpha;'')
 
As is, the object will display in an orthographic projection, which means that z has no bearing on the perspective. To give a perspectice projection, the x and y can be distorted by some equation like:<br />
x = centerx + h / (h-z)
y = centery - h / (h-z)


== Links ==
== Rotation Matrices ==
[http://forums.graalonline.com/forums/showthread.php?t=54167 Amon-ra's explanation and models (continues on p. 2)]
'''Note:''' The following example uses MATLAB notation for the matrix transformation.
[cos(''&gamma;'') sin(''&gamma;'') 0; -sin(''&gamma;'') cos(''&gamma;'') 0; 0 0 1] * ...
[1 0 0; 0 cos(''&alpha;'') sin(''&alpha;''); 0 -sin(''&alpha;'') cos(''&alpha;'')] * ...
[cos(''&beta;'') sin(''&beta;'') 0; -sin(''&beta;'') cos(''&beta;'') 0; 0 0 1] * ...
([x<sub>0</sub> y<sub>0</sub> z<sub>0</sub>]') = [x y z]'

Latest revision as of 10:11, 20 February 2010

Definitions

Euler - Pronounced Oiler; discovered that as 1 is continuously compounded, it reaches a number, e. However, Euler rotation is taking a 3-dimensional axes set and rotating them about the z-axis followed by a forward or backward rotation to create a new axes set. For objects that inherit the property 'eulerrotation', the format is supposedly "Δα Δβ Δγ". Read further for a better explanation.


θ: greek letter theta
φ: greek letter phi
theta and phi are commonly used in trigonometry for angles (but phi is most commonly used as a constant: 1.618...).
α: 1st greek letter alpha. For our purposes, it will represent The angle between the original x axis and the normal vector(1).
β: 2nd greek letter beta. For our purposes, it will represent the forward or backward "tilt".
γ: 3rd greek letter gamma. For our purposes, it will represent the angle between the normal vector(1) and the new x axis.

Therefore, images and text could be rotated, something that could not be done before, so that said image or text would have a three-dimensional effect. If all said is true, eulerrotation = "0 -pi/3 0"; for text would project it in a Star Wars-like fashion.

sin(θ) = y / r (Δy of a point from the center on a circle with radius r)
cos(θ) = x / r (Δx of a point from the center on a circle with radius r)
sin(θ ± φ) = sin(θ) cos(φ) ± cos(θ) sin(φ)
-cos(θ ± φ) = -cos(θ) cos(φ) ± sin(θ) sin(φ)

In addition (not really useful):

tan(θ) = sin(θ) / cos(θ)
cot(θ) = cos(θ) / sin(θ)
sec(θ) = 1 / cos(θ)
csc(θ) = 1 / sin(θ)

(1) The normal vector is the vector perpendicular to the original z and the new z axes. This can be calculated through cross product.

Rotation Matrices

Note: The following example uses MATLAB notation for the matrix transformation.

[cos(γ) sin(γ) 0; -sin(γ) cos(γ) 0; 0 0 1] * ...
[1 0 0; 0 cos(α) sin(α); 0 -sin(α) cos(α)] * ...
[cos(β) sin(β) 0; -sin(β) cos(β) 0; 0 0 1] * ...
([x0 y0 z0]') = [x y z]'