User:Stestagg/3D

A 3D projection is a mathematical transformation used to map three dimensional points onto a two dimensional plane. As most current methods for displaying graphical data are based on two dimensional media, the use of 3D projection is widespread, especially in computer graphics, engineering and drafting. Several common projections are described below.

(Sorry for vanalizing around, but: This page is wrong!!! You have removed the projection and other matrices that are the most important thing about projections. Rotations and translations have nothing to do with projecting and therefore if you want to remove anything or rewrite it, remove those! I'm undoing it again to previous version. Previous article was better, because if you read it through and had enough mathematical knowledge you actually understood how OpenGL works (because the final projection described there is the one from OpenGL). So, add the projection matrices for al the projections and remove simplified non-matrix bullshit (sorry for language, but I'm angry)!)

Orthographic Projection
Orthographic projections are a small set of transforms often used to show profile, detail or precise measurements of a three dimensional object. Common names for orthographic projections include plan, cross-section, birds-eye, and elevation. The normal of the viewing plane (the camera direction) is always parallel to one of the 3D axes making the mathematical transformation very simple. To project the 3D point $$a_x$$, $$a_y$$, $$a_z$$ onto the 2D point $$b_x$$, $$b_y$$ using an Orthographic projection parallel to the y axis(Profile view), the following equation can be used:

b_x = s_x a_x + c_x $$

b_y = s_z a_z + c_z $$ Where the vector s is an arbitrary scale factor, and c is an arbitrary offset. These constants are optional, and can be used to properly align the viewport. The projection can be shown using Matrix notation (introducing a temporary vector d for clarity)

\begin{bmatrix} {d_x } \\ {d_y } \\ \end{bmatrix} = \begin{bmatrix} 1 & 0 & 0 \\   0 & 0 & 1  \\ \end{bmatrix}\begin{bmatrix} {a_x } \\ {a_y } \\ {a_z } \\ \end{bmatrix} $$

\begin{bmatrix} {b_x } \\ {b_y } \\ \end{bmatrix} = \begin{bmatrix} {s_x } & 0 \\ 0 & {s_y } \\ \end{bmatrix}\begin{bmatrix} {d_x } \\ {d_y } \\ \end{bmatrix} + \begin{bmatrix} {c_x } \\ {c_y } \\ \end{bmatrix} $$

Isometric Projection
The Isometric projection is a specific form of Axonometric projection that is particularly suitable for technical diagrams. Each 3D axis is foreshortened by a constant factor ($$\textstyle{\cos 45\over \cos 30}$$), although this factor is often omitted for the sake of simplicity. The isometric transform from $$a_{x,y,z}$$ to $$b_{x,y}$$ can be expressed:

\begin{array}{lcl} b_x &= &(s a_x  - s a_y )\cos 30 \\ b_y &= &(s a_x  + s a_y )\sin 30 + s a_z  \\ \end{array} $$ or with Matrices

\mathbf{b} = s\begin{bmatrix} {\cos 30} & { - \cos 30} & 0 \\ {\sin 30} & {\sin 30} & 1 \\ \end{bmatrix}\mathbf{a} $$ Where $$s$$ should be 0.82 ($$\textstyle{\cos 45\over \cos 30}$$), but can be changed, controlling the scale of the projected image.

It should be noted that traditional pixel art, and older computer games usually use 26.6º($$\arctan 0.5$$) (see Isometric Projection) instead of 30º. This allows lines parallel to the 3D x, or y to be easily drawn without anti-aliasing and does not noticably distort the picture.

Perspective Projection
The Perspective projection requires greater definition. A conceptual aid to understanding the mechanics of this projection involves treating the 2D projection as being viewed through a camera viewfinder. The camera's position, orientation, and field of view control the behaviour of the projection transformation. The following variables are defined to describe this transformation:
 * $$\mathbf{a}_{x,y,z}$$ - a point in 3D space.
 * $$\mathbf{c}_{x,y,z}$$ - the location of the camera.
 * $$\mathbf{\theta}_{x,y,z}$$ - The rotation of the camera. When $$\mathbf{c}_{x,y,z}$$=<0,0,0>, and $$\mathbf{\theta}_{x,y,z}$$=<0,0,0>, the 3D vector <1,0,2> is projected to the 2D vector <1,2>.
 * $$\mathbf{b}_{x,y}$$ - the 2D projection of $$\mathbf{a}$$.

First, we define a point $$\mathbf{d}_{x,y,z}$$ as a translation of point $$\mathbf{a}$$ into a coordinate system defined by $$\mathbf{c}$$. This is achieved by subtracting $$\mathbf{c}$$ from $$\mathbf{a}$$ and then applying a vector rotation matrix using $$-\mathbf{\theta}$$ to the result. This transformation is often called a camera transform:

\begin{bmatrix} \mathbf{d}_x \\ \mathbf{d}_y \\ \mathbf{d}_z \\ \end{bmatrix}=\begin{bmatrix} 1 & 0 & 0 \\   0 & {\cos -\mathbf{\theta}_x } & {\sin -\mathbf{\theta}_x }  \\ 0 & { - \sin -\mathbf{\theta}_x } & {\cos -\mathbf{\theta}_x } \\ \end{bmatrix}\begin{bmatrix} {\cos -\mathbf{\theta}_y } & 0 & { - \sin -\mathbf{\theta}_y } \\ 0 & 1 & 0 \\   {\sin -\mathbf{\theta}_y } & 0 & {\cos -\mathbf{\theta}_y }  \\ \end{bmatrix}\begin{bmatrix} {\cos -\mathbf{\theta}_z } & {\sin -\mathbf{\theta}_z } & 0 \\ { - \sin -\mathbf{\theta}_z } & {\cos -\mathbf{\theta}_z } & 0 \\ 0 & 0 & 1 \\ \end{bmatrix}\left( {\begin{bmatrix}   \mathbf{a}_x  \\   \mathbf{a}_y  \\   \mathbf{a}_z  \\ \end{bmatrix} - \begin{bmatrix}   \mathbf{c}_x  \\   \mathbf{c}_y  \\   \mathbf{c}_z  \\ \end{bmatrix}} \right) $$ Orthogonal transformation Matrix:  Adaptation for n-dimentional arbitrary rotation:  Related form, using rotation around intermediate axes: 

Or, for those less comfortable with matrix multiplication:

\begin{array}{lcl} d_x &= &\cos \theta_y.(\sin \theta_z.(a_y-c_y)+\cos \theta_z.(a_x-c_x))-\sin \theta_y.(a_z-c_z) \\ d_y &= &\sin \theta_x.(\cos \theta_y.(a_z-c_z)+\sin \theta_y.(\sin \theta_z.(a_y-c_y)+\cos \theta_z.(a_x-c_x)))+\cos \theta_x.(\cos \theta_z.(a_y-c_y)-\sin \theta_z.(a_x-c_x)) \\ d_z &= &\cos \theta_x.(\cos \theta_y.(a_z-c_z)+\sin \theta_y.(\sin \theta_z.(a_y-c_y)+\cos \theta_z.(a_x-c_x)))-\sin \theta_x.(\cos \theta_z.(a_y-c_y)-\sin \theta_z.(a_x-c_x)) \\ \end{array} $$ This transformed point can then projected onto the 2D plane using the formula:

\begin{array}{lcl} \mathbf{b}_x &= &\mathbf{d}_x/\mathbf{d}_y \\ \mathbf{b}_y &= &\mathbf{d}_z/\mathbf{d}_y \\ \end{array} $$

Subsequent clipping and scaling operations may be neccessary to map the 2D plane onto any particular display media.

Other Projections
Other common 3D projections include:
 * Fisheye projection - most commonly used in wide-angle photography to create special effects
 * Map projections - Cartographers use numerous projections to represent the earth
 * Stereoscopic projections - utilise color information or light polarity to encode depth information
 * Dimetric and Trimetric projections - relations of the isometric projection