# Crate cgmath [−] [src]

A low-dimensional linear algebra library, targeted at computer graphics.

# Trait overview

In order to make a clean, composable API, we divide operations into traits that are roughly based on mathematical properties. The main ones that we concern ourselves with are listed below:

`VectorSpace`

: Specifies the main operators for vectors, quaternions, and matrices.`MetricSpace`

: For types that have a distance function implemented.`InnerSpace`

: For types that have a dot (or inner) product - ie. vectors or quaternions. This also allows for the definition of operations that are based on the dot product, like finding the magnitude or normalizing.`EuclideanSpace`

: Points in euclidean space, with an associated space of displacement vectors.`Matrix`

: Common operations for matrices of arbitrary dimensions.`SquareMatrix`

: A special trait for matrices where the number of columns equal the number of rows.

Other traits are included for practical convenience, for example:

`Array`

: For contiguous, indexable arrays of elements, specifically vectors.`ElementWise`

: For element-wise addition, subtraction, multiplication, division, and remainder operations.

# The prelude

Importing each trait individually can become a chore, so we provide a
`prelude`

module to allow you to import the main trait all at once. For
example:

use cgmath::prelude::*;

## Reexports

`pub extern crate num_traits;` |

`pub use approx::*;` |

## Modules

conv |
Constrained conversion functions for assisting in situations where type inference is difficult. |

prelude |
This module contains the most common traits used in |

## Macros

assert_relative_eq | |

assert_relative_ne | |

assert_ulps_eq | |

assert_ulps_ne | |

relative_eq |
Predicate for testing the approximate equality of two values. |

relative_ne |
Predicate for testing the approximate inequality of two values. |

ulps_eq |
Predicate for testing the approximate equality of two values using a maximum ULPs (Units in Last Place). |

ulps_ne |
Predicate for testing the approximate inequality of two values using a maximum ULPs (Units in Last Place). |

## Structs

Basis2 |
A two-dimensional rotation matrix. |

Basis3 |
A three-dimensional rotation matrix. |

Decomposed |
A generic transformation consisting of a rotation, displacement vector and scale amount. |

Deg |
An angle, in degrees. |

Euler |
A set of Euler angles representing a rotation in three-dimensional space. |

Matrix2 |
A 2 x 2, column major matrix |

Matrix3 |
A 3 x 3, column major matrix |

Matrix4 |
A 4 x 4, column major matrix |

Ortho |
An orthographic projection with arbitrary left/right/bottom/top distances |

Perspective |
A perspective projection with arbitrary left/right/bottom/top distances |

PerspectiveFov |
A perspective projection based on a vertical field-of-view angle. |

Point1 |
A point in 1-dimensional space. |

Point2 |
A point in 2-dimensional space. |

Point3 |
A point in 3-dimensional space. |

Quaternion |
A quaternion in scalar/vector form. |

Rad |
An angle, in radians. |

Vector1 |
A 1-dimensional vector. |

Vector2 |
A 2-dimensional vector. |

Vector3 |
A 3-dimensional vector. |

Vector4 |
A 4-dimensional vector. |

## Traits

Angle |
Angles and their associated trigonometric functions. |

Array |
An array containing elements of type |

BaseFloat |
Base floating point types |

BaseNum |
Base numeric types with partial ordering |

ElementWise |
Element-wise arithmetic operations. These are supplied for pragmatic reasons, but will usually fall outside of traditional algebraic properties. |

EuclideanSpace |
Points in a Euclidean space with an associated space of displacement vectors. |

InnerSpace | |

Matrix |
A column-major matrix of arbitrary dimensions. |

MetricSpace |
A type with a distance function between values. |

One |
Defines a multiplicative identity element for |

Rotation |
A trait for a generic rotation. A rotation is a transformation that creates a circular motion, and preserves at least one point in the space. |

Rotation2 |
A two-dimensional rotation. |

Rotation3 |
A three-dimensional rotation. |

SquareMatrix |
A column-major major matrix where the rows and column vectors are of the same dimensions. |

Transform |
A trait representing an affine transformation that can be applied to points or vectors. An affine transformation is one which |

Transform2 | |

Transform3 | |

VectorSpace |
Vectors that can be added together and multiplied by scalars. |

Zero |
Defines an additive identity element for |

## Functions

dot |
Dot product of two vectors. |

frustum |
Create a perspective matrix from a view frustrum. |

ortho |
Create an orthographic projection matrix. |

perspective |
Create a perspective projection matrix. |

vec1 |
The short constructor. |

vec2 |
The short constructor. |

vec3 |
The short constructor. |

vec4 |
The short constructor. |