|
|
(7 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 rotation 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. |
|
| |
|
|
| |
|
Line 7: |
Line 8: |
| ''φ'': greek letter ''phi''<br /> | | ''φ'': greek letter ''phi''<br /> |
| ''theta'' and ''phi'' are commonly used in trigonometry for angles (but phi is most commonly used as a constant: 1.618...).<br /> | | ''theta'' and ''phi'' are commonly used in trigonometry for angles (but phi is most commonly used as a constant: 1.618...).<br /> |
| ''α'': 1<sup>st</sup> greek letter ''alpha''. For our purposes, it will represent rotation about the y-axis.<br /> | | ''α'': 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 /> |
| ''β'': 2<sup>nd</sup> greek letter ''beta''. For our purposes, it will represent rotation about the x-axis.<br /> | | ''β'': 2<sup>nd</sup> greek letter ''beta''. For our purposes, it will represent the forward or backward "tilt".<br /> |
| ''γ'': 3<sup>rd</sup> greek letter ''gamma''. For our purposes, it will represent rotation about the z-axis.<br /> | | ''γ'': 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(''θ'') = y / ''r'' (Δy of a point from the center on a circle with radius ''r'') | | sin(''θ'') = y / ''r'' (Δy of a point from the center on a circle with radius ''r'') |
Line 23: |
Line 24: |
| sec(''θ'') = 1 / cos(''θ'') | | sec(''θ'') = 1 / cos(''θ'') |
| csc(''θ'') = 1 / sin(''θ'') | | csc(''θ'') = 1 / sin(''θ'') |
|
| |
| == 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²(''θ'') + cos²(''θ'') = 1
| |
|
| |
| arctan(y/x) = ''θ''; arctan() being the inverse of tangent
| |
| tan(arctan(y/x)) = tan(''θ'')
| |
| y/x = tan(''θ'')
| |
| y/x = ''r'' sin(''θ'') / ''r'' cos(''θ'')
| |
|
| |
| Thus,<br />
| |
| ''r'' sin(''θ'') = y
| |
| ''r'' cos(''θ'') = x
| |
|
| |
| Likewise,
| |
| sin(''θ'') = y / ''r''
| |
| cos(''θ'') = x / ''r''
| |
|
| |
| Plugging into the circle equation, we get
| |
| ''r''² = ''r''² cos²(''θ'') + ''r''² sin²(''θ'')
| |
|
| |
| Compare:
| |
| √(a² + b²) = c (the distance formula)
| |
| x² + y² = ''r''² (established as the equation of a circle)
| |
|
| |
| √(a² + b²) = c
| |
| ( √(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 ''θ''. <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. ''φ'' is a second angle, representing the amount of rotation.<br />
| |
|
| |
| y = ''r'' sin(''θ''), so,
| |
| y = ''r'' sin(''θ'' + ''φ'')
| |
| y = ''r'' ( sin(''θ'') cos(''φ'') + cos(''θ'') sin(''φ'') )
| |
| y = ''r'' sin(''θ'') cos(''φ'') + ''r'' cos(''θ'') sin(''φ'')
| |
| Using substitutions form above, we can simplify to<br />
| |
| y = y cos(''φ'') + x sin(''φ'')
| |
|
| |
| Alternatively,<br />
| |
| x = ''r'' cos(''θ'')
| |
| x = ''r'' cos(''θ'' + ''φ'')
| |
| x = ''r'' ( cos(''θ'') cos(''φ'') - sin(''θ'') sin(''φ'') )
| |
| x = ''r'' cos(''θ'') cos(''φ'') - ''r'' sin(''θ'') sin(''φ'')
| |
| x = x cos(''φ'') - y sin(''φ'')
| |
|
| |
| == Deriving the 3D equations ==
| |
| [[Image:Pointonsphere.png|thumb|right|This image shows how to determine the cartesian coordinates of a point on a sphere in terms of sine and cosine. The point is at the upper tip of the green triangle.]]
| |
| As above, we can change the sphere's equation into a series of distance formulas
| |
| x² + y² + z² = ''r''²
| |
| ( √(x² + y²) )² + z² = ''r''²
| |
| ( √( ( √(x² + y²) )² + z² ) )² = ''r''²
| |
| √( x² + y² + z² ) = ''r''
| |
| ''r''√( ( sin²(''θ'') + cos²(''θ'') ) sin²(''φ'') + cos²(''φ'') ) = ''r''
| |
| √( ( √( sin²(''θ'') + cos²(''θ'') ) )² sin²(''φ'') + cos²(''φ'') ) = 1
| |
| ( sin²(''θ'') + cos²(''θ'') )² sin²(''φ'') + cos²(''φ'') = 1
| |
| sin²(''θ'') sin²(''φ'') + cos²(''θ'') sin²(''φ'') + cos²(''φ'') = 1
| |
|
| |
| Comparing with the original equation we can split it up and get individual equations for x,y, and z.
| |
| y = sin(''θ'') sin(''φ'') <sup>(1)</sup>
| |
| x = cos(''θ'') sin(''φ'') <sup>(1)</sup>
| |
| z = cos(''φ'')
| |
|
| |
| The equation is
| |
| ( sin²(''θ'') + cos²(''θ'') ) ( sin²(''φ'') + cos²(''φ'') ) = 1
| |
|
| |
| So, why doesn't the ( sin²(''θ'') + cos²(''θ'') ) distribute to the cos²(''φ'')? If you'll recall, ( sin²(''θ'') + cos²(''θ'') ) = 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 (''α'', ''β'', and ''γ''). 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>, where ''f'' is a function, x, y, or z).<br />
| |
| x<sub>0</sub> = ''r'' sin(''α'') cos(''β'')
| |
| y<sub>0</sub> = ''r'' sin(''α'') sin(''β'')
| |
| z<sub>0</sub> = ''r'' cos(''α'')
| |
| | |
| 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(''β'') + y sin(''β'')
| |
| ny = y cos(''β'') - z sin(''β'')
| |
| 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(''α'') + z sin(''α'')
| |
| nz = z cos(''α'') - x sin(''α'')
| |
| | |
| x = nx
| |
| | |
| The two-dimensions calculations work for rotations about the z-axis.<br />
| |
| About the z-axis:<br />
| |
| ny = y cos(''γ'') + x sin(''γ'')
| |
| nx = x cos(''γ'') - y sin(''γ'')
| |
| | |
| We expand to simplify:<br />
| |
| | |
| x = x cos(''γ'') - y sin(''γ'')
| |
| x = ( x<sub>0</sub> cos(''α'') + ( z<sub>0</sub> cos(''β'') + y<sub>0</sub> sin(''β'') ) sin(''α'') ) cos(''γ'') - ( y<sub>0</sub> cos(''β'') - z<sub>0</sub> sin(''β'') ) sin(''γ'')
| |
| x = x<sub>0</sub> cos(''α'') cos(''γ'') + z<sub>0</sub> cos(''β'') sin(''α'') cos(''γ'') + y<sub>0</sub> sin(''β'') sin(''α'') cos(''γ'') - y<sub>0</sub> cos(''β'') sin(''γ'') + z<sub>0</sub> sin(''β'') sin(''γ'')
| |
| x = x<sub>0</sub> cos(''α'') cos(''γ'') + y<sub>0</sub> ( sin(''β'') sin(''α'') cos(''γ'') - cos(''β'') sin(''γ'') ) + z<sub>0</sub> ( cos(''β'') sin(''α'') cos(''γ'') + sin(''β'') sin(''γ'') )
| |
| | |
| y = y cos(''γ'') + x sin(''γ'')
| |
| y = ( y<sub>0</sub> cos(''β'') - z<sub>0</sub> sin(''β'') ) cos(''γ'') + ( x<sub>0</sub> cos(''α'') + ( z<sub>0</sub> cos(''β'') + y<sub>0</sub> sin(''β'') ) sin(''α'') ) sin(''γ'')
| |
| y = y<sub>0</sub> cos(''β'') cos(''γ'') - z<sub>0</sub> sin(''β'') cos(''γ'') + x<sub>0</sub> cos(''α'') sin(''γ'') + z<sub>0</sub> cos(''β'') sin(''α'') sin(''γ'') + y<sub>0</sub> sin(''β'') sin(''α'') sin(''γ'')
| |
| y = x<sub>0</sub> cos(''α'') sin(''γ'') + y<sub>0</sub> ( cos(''β'') cos(''γ'') + sin(''β'') sin(''α'') sin(''γ'') ) + z<sub>0</sub> ( -sin(''β'') cos(''γ'') + cos(''β'') sin(''α'') sin(''γ'') )
| |
| | |
| z = z cos(''α'') - x sin(''α'')
| |
| z = ( z<sub>0</sub> cos(''β'') + y<sub>0</sub> sin(''β'') ) cos(''α'') - x<sub>0</sub> sin(''α'')
| |
| z = z<sub>0</sub> cos(''β'') cos(''α'') + y<sub>0</sub> sin(''β'') cos(''α'') - x<sub>0</sub> sin(''α'')
| |
| | |
| As is, the object will display in an orthographic projection, which means that z has no bearing on the perspective. To give a perspective 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(''γ'') 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] * ... |
| | ([x<sub>0</sub> y<sub>0</sub> z<sub>0</sub>]') = [x y z]' |
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]'