... perties.
$$ \mathbf{a} \cdot \mathbf{b} = |\mathbf{a}| |\mathbf{b}| \cos(\theta) $$
This is less interesting until the magnitudes $|\mathbf{a}|$ and $|\mathbf{b}|$ are removed. An immediate relation to the angle $\theta$ can be seen. Due to the expense of trig functions, this is not always that useful. In many cases, explicit angles can be avoided entirely.
$$ \cos(\theta) = \frac{\mathbf{a} \cdot \mathbf{b}}{|\mathbf{a}| |\mathbf{b}|} = \hat{\mathbf{a}} \cdot \hat{\mathbf{b}} $$
$$ \theta = \operatorname{acos}(\hat{\mathbf{a}} \cdot \hat{\mathbf{b}}) $$
$\cos(\theta)$ is quite useful to determine if two vectors are pointing in the same direction, being 1 for the same direction, 0 for right angles and -1 for opposite. It is also used directly as a [diffuse lighting](../lighting/) coefficient.
A far more common use of the dot product is **scalar projection**. $\cos(\theta)$ gives a ratio between the opposite and hypotenuse sides of a right angle triangle. Scaling by $|\mathbf{a}|$ gives the adjacent side length. This gives the distance in the direction of $\mathbf{b}$, an arbitrary vector, that $\mathbf{a}$ travels, unlike the components of $\mathbf{a}$ which give the distance along the basis vectors $x, y, z$.
$$ |\mathbf{a}| \cos(\theta) = \frac{\mathbf{a} \cdot \mathbf{b}}{|\mathbf{b}|} = \mathbf{a} \cdot \hat{\mathbf{b}} $$
![Scalar projection][3]
Scalar projection is used in the introduction of [transformation matrices](/9/rendering/matrices/).
## Cross Product
The cross product of two vectors is another vector, unlike the dot product, perpendicular to the both of the others. Its length is equal to $|\mathbf{a}| |\mathbf{b}| \sin(\theta)$.
$$\mathbf{a} \times \mathbf{b} = |\mathbf{a}| |\mathbf{b}| \sin(\theta) \mathbf{n}$$
A common use is to calculate normals for polygonal meshes as the cross product of two tangent vectors gives a normal. $|\mathbf{a} \times \mathbf{b}|$ also gives the area of a parallelogram formed by $\mathbf{a}$ and $\mathbf{b}$, and half that is the area of the triangle.
#Vector Space
A vector space is a space in which vectors exist. A linear vector space can also be defined by [*basis*](https://en.wikipedia.org/wiki/Basis_(linear_algebra)) vectors. For example, a vector $(1, 2, 3)$ defines magnitudes along the axes $x, y, z$, which form the standard basis in $\mathbb{R}^3$. In other words, the vector $(1, 2, 3)$ represents $1x + 2y + 3z$ where $x, y, z$ are $(1, 0, 0), (0, 1, 0), (0, 0, 1)$.
The same elements forming a vector (1, 2, 3) in another space may be calculated in the standard basis given a mapping between the spaces. This discussion is continued in [matrices](/9/rendering/matrices/).
## Handedness
The handedness, or orientation, of a 3D space is determined by the ordering of the basis vectors. Think of a 2D Cartesian coordinate system drawn on a piece of paper. $+x$ normally points right and $+y$ up. When introducing $z$ is it natural to think of it as pointing up, coming out of the paper towards you. This is a right handed coordinate system. With your *right* hand open, the thumb points towards $+x$, fingers $+y$ and when closing your hand the fingers point towards $+z$. This is a more common coordinate system used by many modelling applications and OpenGL, whereas DirectX is left handed. The choice is somewhat arbitrary, but keeping consistency can avoid having to convert between different systems all the time.
The choice of which axis is considered "up" is also arbitrary. In the paper example above, $+z$ is an obvious choice. However our computer screens are normally in front of us. With $+x$ still pointing right and $+y$ being up. With a right handed coordinate system, $+z$ now points towards us, coming out of the screen.
[1]: /u/img/64448d1347c3.svg
[2]: /u/img/d17cfcee221e.svg
[3]: /u/img/99ae25b67d91.svg(a_1, a_2, a_3) \cdot (b_1, b_2, b_3) \equiv a_1 b_1 + a_2 b_2 + a_3 b_3 $$
$$ \mathbf{a} \cdot \mathbf{b} = |\mathbf{a}| |\mathbf{b}| \cos(\theta) $$
This is less interesting until the magnitudes $|\mathbf{a}|$ and $|\mathbf{b}|$ are removed. An immediate relation to the angle $\theta$ can be seen. Due to the expense of trig functions, this is not always that useful. In many cases, explicit angles can be avoided entirely.
$$ \cos(\theta) = \frac{\mathbf{a} \cdot \mathbf{b}}{|\mathbf{a}| |\mathbf{b}|} = \hat{\mathbf{a}} \cdot \hat{\mathbf{b}} $$
$$ \theta = \operatorname{acos}(\hat{\mathbf{a}} \cdot \hat{\mathbf{b}}) $$
$\cos(\theta)$ is quite useful to determine if two vectors are pointing in the same direction, being 1 for the same direction, 0 for right angles and -1 for opposite. It is also used directly as a [diffuse lighting](../lighting/) coefficient.
A far more common use of the dot product is **scalar projection**. $\cos(\theta)$ gives a ratio between the opposite and hypotenuse sides of a right angle triangle. Scaling by $|\mathbf{a}|$ gives the adjacent side length. This gives the distance in the direction of $\mathbf{b}$, an arbitrary vector, that $\mathbf{a}$ travels, unlike the components of $\mathbf{a}$ which give the distance along the basis vectors $x, y, z$.
$$ |\mathbf{a}| \cos(\theta) = \frac{\mathbf{a} \cdot \mathbf{b}}{|\mathbf{b}|} = \mathbf{a} \cdot \hat{\mathbf{b}} $$
![Scalar projection][3]
Scalar projection is used in the introduction of [transformation matrices](/9/rendering/matrices/).
## Cross Product
The cross product $\times$ of two vectors is another vector, unlike the dot product, perpendicular to the both of the others. Its length is equal to $|\mathbf{a}| |\mathbf{b}| \sin(\theta)$. The order of $\mathbf{a}$ and $\mathbf{b}$ and the space [*handedness*](#handedness) determines which way the result faces.
$$ (a_1, a_2, a_3) \times (b_1, b_2, b_3) \equiv
\begin{vmatrix}
x & y & z \\
a_1 & a_2 & a_3 \\
b_1 & b_2 & b_3
\end{vmatrix}
\equiv (a_2 b_3 - a_3 b_2, a_3 b_1 - a_1 b_3, a_1 b_2 - a_2 b_1) $$
$$\mathbf{a} \times \mathbf{b} = |\mathbf{a}| |\mathbf{b}| \sin(\theta) \mathbf{n}$$
![enter image description here][4]
A common use is to calculate normals for polygonal meshes as the cross product of two tangent vectors gives a normal. $|\mathbf{a} \times \mathbf{b}|$ also gives the area of a parallelogram formed by $\mathbf{a}$ and $\mathbf{b}$, and half that is the area of the triangle. Due to the change in sign, the cross product can be used to find which side of a plane a point lies. Although the cross product is not defined in 2D, the determinant
A combination of the dot and cross product to find $\cos(\theta)$ and $\sin(\theta)$ with the correct sign is useful in combination with the function `atan2` to find $\theta$ over a full circle.
#Vector Space
A vector space is a space in which vectors exist. A linear vector space can also be defined by [*basis*](https://en.wikipedia.org/wiki/Basis_(linear_algebra)) vectors. For example, a vector $(1, 2, 3)$ defines magnitudes along the axes $x, y, z$, which form the standard basis in $\mathbb{R}^3$. In other words, the vector $(1, 2, 3)$ represents $1x + 2y + 3z$ where $x, y, z$ are $(1, 0, 0), (0, 1, 0), (0, 0, 1)$.
The same elements forming a vector (1, 2, 3) in another space may be calculated in the standard basis given a mapping between the spaces. This discussion is continued in [matrices](/9/rendering/matrices/).
## Handedness
The handedness, or orientation, of a 3D space is determined by the ordering of the basis vectors. Think of a 2D Cartesian coordinate system drawn on a piece of paper. $+x$ normally points right and $+y$ up. When introducing $z$ is it natural to think of it as pointing up, coming out of the paper towards you. This is a right handed coordinate system. With your *right* hand open, the thumb points towards $+x$, fingers $+y$ and when closing your hand the fingers point towards $+z$. This is a more common coordinate system used by many modelling applications and OpenGL, whereas DirectX is left handed. The choice is somewhat arbitrary, but keeping consistency can avoid having to convert between different systems all the time.
The choice of which axis is considered "up" is also arbitrary. In the paper example above, $+z$ is an obvious choice. However our computer screens are normally in front of us. With $+x$ still pointing right and $+y$ being up. With a right handed coordinate system, $+z$ now points towards us, coming out of the screen.
[1]: /u/img/64448d1347c3.svg
[2]: /u/img/d17cfcee221e.svg
[3]: /u/img/99ae25b67d91.svg
[4]: /u/img/881c779f4f4d.svg
... perties.
$$ \mathbf{a} \cdot \mathbf{b} = |\mathbf{a}| |\mathbf{b}| \cos(\theta) $$
This is less interesting until the magnitudes $|\mathbf{a}|$ and $|\mathbf{b}|$ are removed. An immediate relation to the angle $\theta$ can be seen. Due to the expense of trig functions, this is not always that useful. In many cases, explicit angles can be avoided entirely.
$$ \cos(\theta) = \frac{\mathbf{a} \cdot \mathbf{b}}{|\mathbf{a}| |\mathbf{b}|} = \hat{\mathbf{a}} \cdot \hat{\mathbf{b}} $$
$$ \theta = \operatorname{acos}(\hat{\mathbf{a}} \cdot \hat{\mathbf{b}}) $$
$\cos(\theta)$ is quite useful to determine if two vectors are pointing in the same direction, being 1 for the same direction, 0 for right angles and -1 for opposite. It is also used directly as a [diffuse lighting](../lighting/) coefficient.
A far more common use of the dot product is **scalar projection**. $\cos(\theta)$ gives a ratio between the opposite and hypotenuse sides of a right angle triangle. Scaling by $|\mathbf{a}|$ gives the adjacent side length. This gives the distance in the direction of $\mathbf{b}$, an arbitrary vector, that $\mathbf{a}$ travels, unlike the components of $\mathbf{a}$ which give the distance along the basis vectors $x, y, z$.
$$ |\mathbf{a}| \cos(\theta) = \frac{\mathbf{a} \cdot \mathbf{b}}{|\mathbf{b}|} = \mathbf{a} \cdot \hat{\mathbf{b}} $$
![Scalar projection][3]
Scalar projection is used in the introduction of [transformation matrices](/9/rendering/matrices/).
## Cross Product
The cross product of two vectors is another vector, unlike the dot product, perpendicular to the both of the others. Its length is equal to $|\mathbf{a}| |\mathbf{b}| \sin(\theta)$.
$$\mathbf{a} \times \mathbf{b} = |\mathbf{a}| |\mathbf{b}| \sin(\theta) \mathbf{n}$$
A common use is to calculate normals for polygonal meshes as the cross product of two tangent vectors gives a normal. $|\mathbf{a} \times \mathbf{b}|$ also gives the area of a parallelogram formed by $\mathbf{a}$ and $\mathbf{b}$, and half that is the area of the triangle.
#Vector Space
A vector space is a space in which vectors exist. A linear vector space can also be defined by [*basis*](https://en.wikipedia.org/wiki/Basis_(linear_algebra)) vectors. For example, a vector $(1, 2, 3)$ defines magnitudes along the axes $x, y, z$, which form the standard basis in $\mathbb{R}^3$. In other words, the vector $(1, 2, 3)$ represents $1x + 2y + 3z$ where $x, y, z$ are $(1, 0, 0), (0, 1, 0), (0, 0, 1)$.
The same elements forming a vector (1, 2, 3) in another space may be calculated in the standard basis given a mapping between the spaces. This discussion is continued in [matrices](/9/rendering/matrices/).
## Handedness
The handedness, or orientation, of a 3D space is determined by the ordering of the basis vectors. Think of a 2D Cartesian coordinate system drawn on a piece of paper. $+x$ normally points right and $+y$ up. When introducing $z$ is it natural to think of it as pointing up, coming out of the paper towards you. This is a right handed coordinate system. With your *right* hand open, the thumb points towards $+x$, fingers $+y$ and when closing your hand the fingers point towards $+z$. This is a more common coordinate system used by many modelling applications and OpenGL, whereas DirectX is left handed. The choice is somewhat arbitrary, but keeping consistency can avoid having to convert between different systems all the time.
The choice of which axis is considered "up" is also arbitrary. In the paper example above, $+z$ is an obvious choice. However our computer screens are normally in front of us. With $+x$ still pointing right and $+y$ being up. With a right handed coordinate system, $+z$ now points towards us, coming out of the screen.
[1]: /u/img/64448d1347c3.svg
[2]: /u/img/d17cfcee221e.svg
[3]: /u/img/99ae25b67d91.svg(a_1, a_2, a_3) \cdot (b_1, b_2, b_3) \equiv a_1 b_1 + a_2 b_2 + a_3 b_3 $$
$$ \mathbf{a} \cdot \mathbf{b} = |\mathbf{a}| |\mathbf{b}| \cos(\theta) $$
This is less interesting until the magnitudes $|\mathbf{a}|$ and $|\mathbf{b}|$ are removed. An immediate relation to the angle $\theta$ can be seen. Due to the expense of trig functions, this is not always that useful. In many cases, explicit angles can be avoided entirely.
$$ \cos(\theta) = \frac{\mathbf{a} \cdot \mathbf{b}}{|\mathbf{a}| |\mathbf{b}|} = \hat{\mathbf{a}} \cdot \hat{\mathbf{b}} $$
$$ \theta = \operatorname{acos}(\hat{\mathbf{a}} \cdot \hat{\mathbf{b}}) $$
$\cos(\theta)$ is quite useful to determine if two vectors are pointing in the same direction, being 1 for the same direction, 0 for right angles and -1 for opposite. It is also used directly as a [diffuse lighting](../lighting/) coefficient.
A far more common use of the dot product is **scalar projection**. $\cos(\theta)$ gives a ratio between the opposite and hypotenuse sides of a right angle triangle. Scaling by $|\mathbf{a}|$ gives the adjacent side length. This gives the distance in the direction of $\mathbf{b}$, an arbitrary vector, that $\mathbf{a}$ travels, unlike the components of $\mathbf{a}$ which give the distance along the basis vectors $x, y, z$.
$$ |\mathbf{a}| \cos(\theta) = \frac{\mathbf{a} \cdot \mathbf{b}}{|\mathbf{b}|} = \mathbf{a} \cdot \hat{\mathbf{b}} $$
![Scalar projection][3]
Scalar projection is used in the introduction of [transformation matrices](/9/rendering/matrices/).
## Cross Product
The cross product $\times$ of two vectors is another vector, unlike the dot product, perpendicular to the both of the others. Its length is equal to $|\mathbf{a}| |\mathbf{b}| \sin(\theta)$. The order of $\mathbf{a}$ and $\mathbf{b}$ and the space [*handedness*](#handedness) determines which way the result faces.
$$ (a_1, a_2, a_3) \times (b_1, b_2, b_3) \equiv
\begin{vmatrix}
x & y & z \\
a_1 & a_2 & a_3 \\
b_1 & b_2 & b_3
\end{vmatrix}
\equiv (a_2 b_3 - a_3 b_2, a_3 b_1 - a_1 b_3, a_1 b_2 - a_2 b_1) $$
$$\mathbf{a} \times \mathbf{b} = |\mathbf{a}| |\mathbf{b}| \sin(\theta) \mathbf{n}$$
![enter image description here][4]
A common use is to calculate normals for polygonal meshes as the cross product of two tangent vectors gives a normal. $|\mathbf{a} \times \mathbf{b}|$ also gives the area of a parallelogram formed by $\mathbf{a}$ and $\mathbf{b}$, and half that is the area of the triangle. Due to the change in sign, the cross product can be used to find which side of a plane a point lies. Although the cross product is not defined in 2D, the determinant
A combination of the dot and cross product to find $\cos(\theta)$ and $\sin(\theta)$ with the correct sign is useful in combination with the function `atan2` to find $\theta$ over a full circle.
#Vector Space
A vector space is a space in which vectors exist. A linear vector space can also be defined by [*basis*](https://en.wikipedia.org/wiki/Basis_(linear_algebra)) vectors. For example, a vector $(1, 2, 3)$ defines magnitudes along the axes $x, y, z$, which form the standard basis in $\mathbb{R}^3$. In other words, the vector $(1, 2, 3)$ represents $1x + 2y + 3z$ where $x, y, z$ are $(1, 0, 0), (0, 1, 0), (0, 0, 1)$.
The same elements forming a vector (1, 2, 3) in another space may be calculated in the standard basis given a mapping between the spaces. This discussion is continued in [matrices](/9/rendering/matrices/).
## Handedness
The handedness, or orientation, of a 3D space is determined by the ordering of the basis vectors. Think of a 2D Cartesian coordinate system drawn on a piece of paper. $+x$ normally points right and $+y$ up. When introducing $z$ is it natural to think of it as pointing up, coming out of the paper towards you. This is a right handed coordinate system. With your *right* hand open, the thumb points towards $+x$, fingers $+y$ and when closing your hand the fingers point towards $+z$. This is a more common coordinate system used by many modelling applications and OpenGL, whereas DirectX is left handed. The choice is somewhat arbitrary, but keeping consistency can avoid having to convert between different systems all the time.
The choice of which axis is considered "up" is also arbitrary. In the paper example above, $+z$ is an obvious choice. However our computer screens are normally in front of us. With $+x$ still pointing right and $+y$ being up. With a right handed coordinate system, $+z$ now points towards us, coming out of the screen.
[1]: /u/img/64448d1347c3.svg
[2]: /u/img/d17cfcee221e.svg
[3]: /u/img/99ae25b67d91.svg
[4]: /u/img/881c779f4f4d.svg